Why does an error saying "Unrecognised function or variable" occrurs while solving a two variable polynomial equation numerically using vpasolve
3 次查看(过去 30 天)
显示 更早的评论
I am trying to solve a bi variable polynomial equation x^4+3*x^2+x*t==0, where t is an independent variable and x is the dependent variable and I want to plot the results as well. So I use the help of vpasolve to get the results over a range of values for the independent variable 't'. I used the following code
clc;clear;close all;
sym x;
sym t;
t= 0.1:0.01:1;
for i= length(t)
S(i)= vpasolve(x^4+3*x^2+x*t==0,x);
end
plot(x,t)
If I run the above code I receive the following error
Unrecognized function or variable 'x'.
Error in sample_polynomial_equation_trial (line 6)
S(i)= vpasolve(x^4+3*x^2+x*t==0,x);
What correction should be done in order to get the code running? I am using MATLAB version R2020a
0 个评论
采纳的回答
Star Strider
2022-1-30
Needs parentheses, single quotes, and some other tweaks —
% clc;clear;close all;
x = sym('x');
% sym(t);
t= 0.1:0.01:1;
for i= length(t)
S(:,i)= vpasolve(x^4+3*x^2+x*t(i)==0,x);
end
figure
subplot(2,1,1)
plot(t,real(double(S)))
grid
xlim([0.99 1.00])
subplot(2,1,2)
plot(t, imag(double(S)))
grid
xlim([0.99 1.00])
.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!