Doubt in MATLAB coding.
显示 更早的评论
Hello. I'm trying to plot a differntial equation using MATLAB. When I run my program, I'm getting different graph.
I've attached the differential equation and my MATLAB coding below.
Can anyone tell me how to use the boundary conditions correctly?

function abcd
ex4init=bvpinit(linspace(0.00001,100,21),[0,0]);
sol=bvp4c(@ex4ode,@ex4bc,ex4init)
plot(sol.x,sol.y(1,:),'blue');
end
function f=ex4ode(r,y)
a=0.001391304348;
b=19.31459475;
f=[y(2)
-(2/r)*y(2)-a*(1-exp(b*y(1)))
];
end
function res=ex4bc(ya,yb)
res=[
ya(1)+1
yb(2)
]
end
This is the graph which I got.

But this is the exact graph.

2 个评论
Robert U
2020-3-4
Hi Joy Salomi,
Check your x axis range. I suppose the values should be in nm, i.e. 1e-9 m.
Kind regards,
Robert
Joy Salomi
2020-3-4
采纳的回答
更多回答(2 个)
Constantino Carlos Reyes-Aldasoro
2020-3-4
This is a bit hard to solve without knowing more of the problem. What I would do is to break down the problem and analyse each step. For example, look at the values you have in the solution "sol". I plot separately:
>> plot(sol.x);
>> plot(sol.y);


And also
>> plot(sol.y');

Is anything here remotely connected to what you are expecting? My guess is that no, sol.y has values between 0 and 12e4 whilst the graph you want is between -1 and 0. So the problem is not really about Matlab but about the equations that you are using.
Hope this helps.
Robert U
2020-3-4
Hi Joy Salomi,
the implementation of a boundary value problem with singular term has to be done a bit different than you did.
--> doc: Solve BVP with Singular Term
function abcd
ex4init=bvpinit(linspace(0,100,5),[-1 0]);
S = [0 0; 0 -2];
options = bvpset('SingularTerm',S);
sol=bvp4c(@ex4ode,@ex4bc,ex4init,options);
plot(sol.x,sol.y(1,:),'blue');
end
function f=ex4ode(r,y)
a=0.001391304348;
b=19.31459475;
f = [ y(2)
-a*(1-exp(b*y(1))) ];
end
function res=ex4bc(ya,yb)
res=[ ya(1)+1
yb(2) ];
end
Using the values "a" and "b" you supplied still leads to a singular Jacobian matrix which provoces an error. Changing both these values to one leads to a solution that qualitatively corresponds to the curves drawn.
There are two more points that hinder me to test my solution:
- I don't know how "a" and "b" translate to "phi_s".
- I still assume that r is given in SI units. If r is in unit [m] the interval needs to be adjusted to [nm] as shown in your graph.
Kind regards,
Robert
4 个评论
Joy Salomi
2020-3-5
编辑:Joy Salomi
2020-3-5
Joy Salomi
2020-3-5
编辑:Joy Salomi
2020-3-5
Robert U
2020-3-5
Hi Joy Salomi,
maybe you can state what physical process is described by that differential equation and what reference you are using (where is your photo from).
I still think that your values for a and b do not correspond to the case that is depicted in the book/article.
Kind regards,
Robert
Joy Salomi
2020-3-5
编辑:Joy Salomi
2020-3-5
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


