Effacer les filtres
Effacer les filtres

函数或变量 'poly2str' 无法识别,如何导入poly2str?

89 vues (au cours des 30 derniers jours)
Ran
Ran le 12 Oct 2023
Commenté : 慧敏 le 10 Mai 2024
x=-2*pi:pi/2:2*pi;
y=[1,0,-1,0,1,0,-1,0,1];
p2=polyfit(x,y,2);
p3=polyfit(x,y,3);
p4=polyfit(x,y,4);
p6=polyfit(x,y,6);
disp('二次拟合函数'),f2=poly2str(p2,'x');
disp('三次拟合函数'),f3=poly2str(p3,'x');
disp('四次拟合函数'),f4=poly2str(p4,'x');
disp('七次拟合函数'),f6=poly2str(p6,'x');
x1=-2*pi:pi/10:2*pi;
y2=polyval(p2,x1);
y3=polyval(p3,x1);
y4=polyval(p4,x1);
y6=polyval(p6,x1);
yy=cos(x1);
plot(x,y,x1,y2,'-b',x1,y3,'-.r',x1,y4,'*c',x1,y6,'.g',x1,yy);

Réponse acceptée

Yash
Yash le 18 Oct 2023
Hi Ran,
我会用英语回答
I understand that you want to use "poly2str" function to return polynomial as string. I tried reproducing the error "Unrecognized function or variable 'poly2str'" on my end. However, I didn't encounter any error. Consider running the following command in the MATLAB command window to check if "poly2str.m" is present on the root path:
>> which poly2str -all
If "poly2str.m" is not found by "which", then consider running the following command in the MATLAB command window to refresh function and file system path cache:
>> rehash toolboxcache
If "poly2str.m" is still not found by "which", then verify if "Control System" toolbox is installed or not. Refer here for more information on installing a toolbox: https://www.mathworks.com/matlabcentral/answers/101885-how-do-i-install-additional-toolboxes-into-an-existing-installation-of-matlab
Alternatively, consider using the function "poly2sym" to create symbolic polynomial from vector of coefficients. Refer here for more information on "poly2sym" function: https://www.mathworks.com/help/releases/R2023a/symbolic/sym.poly2sym.html
>> p = poly2sym([0.75, -0.5, 0.25])
p =
(3*x^2)/4 - x/2 + 1/4
I hope this helps!
  2 commentaires
Ran
Ran le 19 Oct 2023
Thank you very much!It helps me a lot and solves my homework i have been struggling with.
慧敏
慧敏 le 10 Mai 2024
请问最后是怎么解决的?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 安装和许可简介 dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!