solving ode equation using ode45

15 次查看(过去 30 天)
I have an ode which I need to solve with respect to the time variable.
I have 2 seperate scripts, one contains the function and the other contains the command.
my function is,
===================================
function dy_dt=func(t,y)
dy_dt=0.003445*((y-0.072)/y^3)^0.5;
end
===================================
In the other script I have,
===================================
clc, clear, close all
time=0:0.05:8.5;
[t,y]=ode45(@myfun1,time,0.073);
plot(t,y(:,1));
==================================
When the initial value for y=0.072 I get the following graph;
because y=0.072 leads to an erroneous graph I decided to give y=0.073 as the initial value for which I got the following graph;
This is also erroneous as this is not the result I expect. The graph I expect is attached below.
Can someone assist me on what errors I have done in my code? Thank you very much.
  12 个评论
James Tursa
James Tursa 2021-2-20
Because OP wrote:
"... initial value for y=0.072 ..."
Some clarification from OP would help here, as well as some info on where this differential equation comes from.
David Goodmanson
David Goodmanson 2021-2-20
I agree about clarification from the OP, who wrote "When the initial value for y=0.072 I get the following graph" but who also later wrote "I decided to give y=0.073 as the initial value" so it did not appear to me that the initial value = y0 was set in stone.

请先登录,再进行评论。

回答(1 个)

David Goodmanson
David Goodmanson 2021-2-19
编辑:David Goodmanson 2021-2-20
Hi nadeeshani,
UPDATED ANSWER
This is a speculative answer, but perhaps you did not take the square root when you calculated the constant. At any rate, plugging in sqrt(.003445) = 0.0587 in place of .003445 (NOTE: and using initial value 0.073) gives a plot that is very close to the expected one.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by