Operator '*' is not supported for operands of type 'function_handle'.

5 views (last 30 days)
nune pratyusha
nune pratyusha on 20 May 2022
Edited: Torsten on 20 May 2022
clc; clear all;
format compact; format long e;
set(0,'defaultaxesfontsize',16.5,'defaultaxeslinewidth',0.8,...
'defaultlinelinewidth',2.0,'defaultpatchlinewidth',2.7,...
'defaultaxesfontweight','Bold')
b=0.4;c=11;d=6;e=130;f=10;m=1;
global a
brange = 5:1:12.2;
k = 0; tspan = 0:1e-1:70;
xmax = [];
for a = brange
a
j = 1; k = k + 1;
f = @(t,x) [a*x(2)+(0.2+0.2.*abs(x(4))).*x(3);b*((x(4).^2)-13).*x(3)-c*x(2);-d*x(1)-e*x(2)-f*x(3);(x(3).^2)-x(4).^2];
x0 = [0 0 1 1];
[t,x] = ode15s(f,tspan,x0);
count = find(t>10);
x = x(count,:);
j = 1;
n = length(x(:,1));
for i=2 : n-1
if (x(i-1,1)+eps) < x(i,1) && x(i,1) > (x(i+1,1)+eps)
xmax(k,j)=x(i,1);
j=j+1;
end
end
if j>1
plot(a,xmax(k,1:j-1),'k.');
end
hold on;
index(k)=j-1;
end
xlabel('Bifurcation parameter b');
ylabel('x max');
title('Bifurcation diagram for b');
error is like:
a =
5
a =
6
Operator '*' is not supported for operands of type 'function_handle'.
Error in double_mem_bif>@(t,x)[a*x(2)+(0.2+0.2.*abs(x(4))).*x(3);b*((x(4).^2)-13).*x(3)-c*x(2);-d*x(1)-e*x(2)-f*x(3);(x(3).^2)-x(4).^2] (line 16)
f = @(t,x) [a*x(2)+(0.2+0.2.*abs(x(4))).*x(3);b*((x(4).^2)-13).*x(3)-c*x(2);-d*x(1)-e*x(2)-f*x(3);(x(3).^2)-x(4).^2];
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 152)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in double_mem_bif (line 18)
[t,x] = ode15s(f,tspan,x0);
>>

Answers (1)

Steven Lord
Steven Lord on 20 May 2022
b=0.4;c=11;d=6;e=130;f=10;m=1;
% ...
f = @(t,x) [a*x(2)+(0.2+0.2.*abs(x(4))).*x(3);b*((x(4).^2)-13).*x(3)-c*x(2);-d*x(1)-e*x(2)-f*x(3);(x(3).^2)-x(4).^2];
Change the name of your anonymous function so it doesn't overwrite the constant f you defined above. Use that new name when you call ode15s.

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!