Why does an error saying "Unrecognised function or variable" occrurs while solving a two variable polynomial equation numerically using vpasolve

4 次查看(过去 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
Unrecognized function or variable 'x'.
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

采纳的回答

Star Strider
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 个)

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by