Function to display polynomial based on user input
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Geoff Hayes
le 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.
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!