Error in script - 'undefined function'

Hi all!
I'm new to Matlab so am encountering many problems. Here, I have written a script laying out the variables of an ODE which I will later attempt to solve using ode45. However, when I try to call the function it gives me this messgae. (Context: Xo and Xi are the volumes of water in the outer and inner layer of a leaf respectively, where Xo + Xi = 1).
I have tried to figure out the problem using online help but to no avail so any help would be greatly appreciated!

回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 17 日

0 投票

Xi must be a numerical value , in your case you didn't define it which causes error

9 件のコメント

Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
Thanks for your response!
My ODEs though are in terms of Xo and Xi and all the other variable stated (a, b, Uh etc):
ode2.png
ode1.png
Do you have any idea how I could go about solving these? (Am I on the right track with creating a script that defines the variables?)
Thanks
madhan ravi
madhan ravi 2018 年 11 月 17 日
編集済み: madhan ravi 2018 年 11 月 17 日
I have no idea what you did but I solved it in terms as function of t
t=[0 1]; %time interval
y0=[0 0] %initial conditions
[t,x]=ode45(@myod,t,y0);
plot(t,x)
function dxdt = myod(t,x)
%x(1)->Xo
%x(2)->Xi
a=3600;
b=3600;
uh=3; %fake data
ua=2; %fake data
uc=7; %fake data
mu=7; %fake data
x(1)=1-x(2);
dxdt=zeros(2,1);
dxdt(1)=(a*x(1).^2)./(x(1).^2+x(2).^2)+uh+ua-uc-mu.*x(1);
dxdt(2)=(a*x(2).^2)./(x(1).^2+x(2).^2)-uh-ua+uc-mu.*x(2);
end
Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
Impressive! Thanks very much, I'll give that a go! Does all of that go in the command window or do I need to create a file in the editor? (Also where are you getting the values or 3, 2 and 7 for the u terms?)
madhan ravi
madhan ravi 2018 年 11 月 17 日
As mentioned earlier the values have to be numerical, you can copy my answer and save it as a script file and then run it
Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
Their values are dependent on Xo and Xi though.
I will send you the article I have taken all of this from as I haven't explained the context! Here you can see all their parameter values and their graphs of results (which I am trying to replicate - to not much success as you can see!).
Stephen23
Stephen23 2018 年 11 月 17 日
"Their values are dependent on Xo and Xi though."
Then parameterize the function using either nested functions or an anonymous function:
Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
I'll check that out, thanks!
Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
I've run into another problem which I can't work out - I'm trying to work through the example on the page you sent me. However when I try to call the saved function in the command window I get this message - any ideas?
findzero.png
Daniella Crispi
Daniella Crispi 2018 年 11 月 17 日
Oops - just realised the values I typed in the command line are slightly different to those in the example. (However I retyped it correctly and the same message shows).

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

カテゴリ

質問済み:

2018 年 11 月 17 日

コメント済み:

2018 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by