Function to display polynomial based on user input

1 visualización (últimos 30 días)
Mitchell
Mitchell el 1 de Mzo. de 2019
Editada: Mitchell el 1 de Mzo. de 2019
function polynom3 ()
%This function outputs a third-order polynomial function with coefficients
%as the input variables
w=input('cubed term \n');
x=input('squared term \n');
y2=input('x-term \n');
z=input('constant term one \n');
z2=input('constant term two \n');
z3=input('constant term three \n');
z4=input('constant term fourb \n ');
fprintf('y=%d(z).^%d(w)+%d(z2).^%d(x)+%d(z3).^%d(y2)+%d(z4)\n',w,x,y2,z,z2,z3,z4)
I'm wanting a 3rd degree polynomial but it out puts wrong
this is what it is outputting:
y=(1(z).^2(w))+(3(z2).^4(x))+(5(z3).^6(y2))+(7(z4))
How do I get it to display as a regular ploynomial function

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 1 de Mzo. de 2019
MItchell - I think that you are confusing some of your variables as exponents. Wouldn't the code be more like
fprintf('y=%d(x)^3 + %d(x)^2 + %d(x) + %d + %d + %d + %d)\n',w,x,y2,z,z2,z3,z4)
I may be misunderstanding what your inputs are supposed to represent - you may want to rename them differently and/or organize the data in a different manner.
  1 comentario
Mitchell
Mitchell el 1 de Mzo. de 2019
Editada: Mitchell el 1 de Mzo. de 2019
Thank you for pointing that out!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by