Function to display polynomial based on user input

8 次查看(过去 30 天)
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

采纳的回答

Geoff Hayes
Geoff Hayes 2019-3-1
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by