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

4 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 30 Jan 2022
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])
.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!