How do you fix a 'function_handle' error?

23 ビュー (過去 30 日間)
John Morabito
John Morabito 2019 年 5 月 3 日
回答済み: Jan 2019 年 5 月 3 日
I am trying to solve an IVP by using an ODESolver function that calls two other defined functions. I keep getting a message saying, "Undefined function 'ODESolver1' for input arguments of type 'function_handle'. " I don't know how to fix this.
Below is the ODESolver function that I have created
function[X,Y] = ODESolver1(Integrator,RHS,A,B,YA,DX)
NI = int64(((B-A)/DX)+1);%Number of Integration Steps
X = zeros(NI,1);
Y = zeros(NI,1);
%Initial Condition
X(1)=A;
Y(1)=YA;
for i = 1:NI-1
[X(i+1),Y(i+1)]=Integrator(X(i),Y(i),DX,RHS);
end
end
And now this is my script that keeps getting me function_handle errors
[X1,Y1] = ODESolver1(@Euler,@HK20,0,0.2,0.4,0.01)
[X2,Y2] = ODESolver1(@Euler,@HK30,0,0.2,0.4,0.01)
[X3,Y3] = ODESolver1(@Euler,@HK40,0,0.2,0.4,0.01)
figure (1)
plot(X1,Y1,X2,Y2,X3,Y3)
xlabel('Time')
ylabel('H Concentration')
legend('K20','K30','K40')
  4 件のコメント
John Morabito
John Morabito 2019 年 5 月 3 日
編集済み: Jan 2019 年 5 月 3 日
This is my Euler function:
function [X,Y]=Euler(X0,Y0,DX,RHS)
F=RHS(X0,Y0);
Y=Y0+DX*F;
X=X0+DX;
end
And this is my concentration function:
function [F] HK20(t,L)
K = 20;
L = .4*exp(-K*t);
M = -K*L;
end
Jan
Jan 2019 年 5 月 3 日
There is a missing "=" in the definition of HK20()

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2019 年 5 月 3 日
Where is thze function ODESolver1 stored? In an M-files called "ODESolver1.m"? Is this stored in a folder, which is contained in the path? The error message means, that this function is not found, so either there is a typo in the file name or the parent folder is not contained in Matlab's path.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by