asd
asd

Reputation: 337

error message in ode15s code

I wrote these simple codes in matlab in the separate files. When I run this program, I get this message:

??? Attempt to execute SCRIPT ode15s as a function:

D:\app\ode15s.m

Error in ==> ode15s at 2

[T,Y] = ode15s(@difdif,[0 40],[1 0 0]);

what's the problem.

««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

clc

[T,Y] = ode15s(@difdif,[0 40],[1 0 0]);

%plot(T,Y(:,3),'-o')

plot(T,Y(:,1),'-',T,Y(:,2),'-o',T,Y(:,3),'.')

«««««««««««««««««««««««««««««««««««««««««««««««««««

function dy = difdif(t,y)

dy = zeros(3,1);    % a column vector

dy(1) =-0.04*y(1)+10^4*y(2)*y(3);

dy(2) = 0.04*y(1)-10^4*y(2)*y(3)-3*10^7*y(2)^2;

dy(3) = 3*10^7*y(2)^2;

end

Upvotes: 0

Views: 561

Answers (2)

Marc
Marc

Reputation: 3313

You named your script as ode15s, the same name as the built-in function. When matlab attempts to execute ode15s(@difdif,[0 40],[1 0 0]), it finds the script, not the built-in function. Rename your script.

Upvotes: 0

zellus
zellus

Reputation: 9592

Why do I receive the error "Attempt to execute SCRIPT FILENAME as a function"? deals with your issue. D:\app\ode15s.m is possibly a self made script that comes first on the MATLAB search path. MATLAB's built in ode15s.m won't be called as intended. Change the order in your MATLAB search path or rename D:\app\ode15s.m.

Quoting the solution: which ode15s -all shows you all instances on your search path.

Upvotes: 2

Related Questions