discrete fixed point and their stability
5 views (last 30 days)
Show older comments
What is the rong with my code?
there is an error message "Conversion to logical from sym is not possible."
clc;
clear all;
syms xn xe
assume(0<xn<=1)
r=input('Enter the value of production rate','s')
f(xn)=r*xn*(1-xn);
eq=xe==subs(f,xn,xe)
display('The equilibrium points are:')
xe=solve(eq)
df=diff(r*xn*(1-xn),xn)
eq1=subs(df,xn,xe);
t=length(eq1);
eq1=double(eq1);
for i=1:t
if eq(i)>1;
fprintf('The equilibrium point %g is unstable',eq(i))
elseif eq(i)<-1;
fprintf('The equilibrium point %g is unstable',eq(i))
elseif 0<eq(i)&&eq(i)<1
fprintf('The equilibrium point %g is stable',eq(i))
else -1<eq(i)&&eq(i)<0
fprintf('The equilibrium point %g is stable',eq(i))
end
end
0 Comments
Answers (2)
Walter Roberson
on 5 Nov 2023
Moved: Walter Roberson
on 5 Nov 2023
for r = -2:0.25:5
syms xn xe
assume(0<xn<=1)
f(xn)=r*xn*(1-xn);
eq=xe==subs(f,xn,xe);
fprintf('r = %g, The equilibrium points are:\n', r)
xe=solve(eq);
disp(char(xe))
df = diff(r*xn*(1-xn),xn);
eq1 = simplify(subs(df,xn,xe));
t = length(eq1);
eq1 = double(eq1);
for i=1:t
if eq1(i)>1
fprintf('r = %g, The equilibrium point %g is unstable',r,eq1(i));
elseif eq1(i)<-1
fprintf('r = %g, The equilibrium point %g is unstable',r,eq1(i));
elseif 0<eq1(i)&&eq1(i)<1
fprintf('r = %g, The equilibrium point %g is stable',r,eq1(i));
elseif -1<eq1(i)&&eq1(i)<0
fprintf('r = %g, The equilibrium point %g is stable',r,eq1(i));
else
fprintf('r = %g, failed to classify %g\n', r, eq1(i));
end
end
fprintf('\n-----\n');
end
0 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!