简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM