Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
How can i use polyval on the input polynomial question?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
prompt={'Input Equation:','Value of the variable:'};
dgtitle='Evaluate at a Given Value';
evans=inputdlg(prompt,dgtitle);
eq=str2sym(evans{1});
val=str2double(evans{2});
cf=coeffs(eq);
c=fliplr(cf);
k=polyval(str2double(c),val);
display(k)
k =
NaN
My program should ask for equation and the value of the variable. What did i do wrong?
0 commentaires
Réponses (1)
David Hill
le 28 Oct 2020
Why not just enter the polynomial coefficents instead of an equation?
p=input('Polynomial coefficents, (like [1 2 3 4]):');
val=input('Evaluate at this value');
k=polyval(p,val);
display(k)
2 commentaires
David Hill
le 28 Oct 2020
Use regexp() function
y='5x^3+2x^2+3x+5';%requires 1 in front of x's
p=str2double(regexp(y,'(?<!\^)\d*','match'));
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!