How to integrate this function using ode23?
显示 更早的评论
The given function is as follows:

I've written the following code:
clc
clear all
tspan = [0 10];
y0 = 0;
%[t,y] = ode23(@(t,y) 2*t, tspan, y0);
Minc = 67;
Mp = 12;
dfe = 7200;
din = 4040;
Dp = 5e-5;
Cl = 0.045;
Cleq = 0.005;
z = (Minc/(100*Mp))*(dfe/din)*Dp*(Cl - Cleq) ;
disp( z)
[t,y] = ode23(@(t,y) (1/y)*(Minc/(100*Mp))*(dfe/din)*Dp*(Cl - Cleq), tspan, y0);
plot(t,y,'-o');
8 个评论
Ameer Hamza
2020-3-14
编辑:Ameer Hamza
2020-3-14
Your code is correct. But the behavior shown by ode23 and other function of ode-suite is quite strange. We know that even an analytical solution exists for your ODE with given initial conditions. But somehow, ode23 is calculating all the values of y to be NaN. After a bit of fiddling, it can be seen that the issue is caused by setting the initial condition to be zero. If you increase the initial condition even by a ridiculously tiny amount, the ode45 will give a solution. For example, change the initial condition to be
y0 = 1e-308; % minimum possible exponent for double
Maybe this is a bug. Maybe someone else here can come up with a valid reason why it should happen.
Anshuman S
2020-3-14
Ameer Hamza
2020-3-14
编辑:Ameer Hamza
2020-3-14
For such problems, both ode23 and ode45 should work fine. I mistakenly wrote ode45 in my comment. I wanted to write ode23. I have also added this as an answer so that anyone facing this error in the future can easily find the fix.
Anshuman S
2020-3-14
Ameer Hamza
2020-3-14
I am not sure about this one. Changing the initial condition to some other values helps but I am not sure this is what you want
tspan = [0.5 10];
y0 = 0.5;
Using a stiff solver also seems to help
[t,y] = ode15s(@(t,y) (-(alpha*Dp/(2*y)) - (alpha/2)*sqrt(Dp/(3.1415*t))), tspan, y0);
But In this case, this might be the property of the differential equation itself.
Anshuman S
2020-3-14
Anshuman S
2020-3-14
Ameer Hamza
2020-3-14
I was trying different values and this is the one I pasted here. This following one works too
tspan = [1e-308 10];
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
