Function to display polynomial based on user input
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Geoff Hayes
on 1 Mar 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.
More Answers (0)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!