Unable to solve the collocation equations -- a singular Jacobian encountered.
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm new to Matlab and have a simple question. I'd like to plot h=x*y, where y takes the form of an ODE. How do I plot h in this x interval, [0,4]?
My code is:
syms y Dy D2y x Y
ode = y-(1/(Dy/y+(D2y*x)/y))^2;
ode1 = solve(ode==0,D2y);
ode2 = matlabFunction(ode1);
odefcn = @(x,y)[y(2);f(y(2),x,y(1))];
bcfcn = @(ya,yb)[ya(1)-2;yb(1)];
xmesh = linspace(0,4,10);
solinit = bvpinit(xmesh, [0 0]);
sol = bvp4c(odefcn,bcfcn,solinit);
plot(sol.x,sol.y(1,:))
0 个评论
采纳的回答
Torsten
2023-5-8
编辑:Torsten
2023-5-8
You have an ODE that has a singularity at x=0. Further, solving for D2y leads to two different differential equations. You must decide which is the one you want to solve.
Thus the results below should be treated with care.
syms y Dy D2y x Y
ode = y-(1/(Dy/y+(D2y*x)/y))^2;
ode1 = solve(ode==0,D2y)
ode2 = matlabFunction(ode1(1),'Vars',{x,[y Dy]})
odefcn = @(x,y)[y(2);ode2(x,[y(1),y(2)])];
bcfcn = @(ya,yb)[ya(1)-2;yb(1)];
xmesh = linspace(1e-3,4,10);
solinit = bvpinit(xmesh, [1 1]);
sol = bvp4c(odefcn,bcfcn,solinit);
plot(sol.x,sol.x.*sol.y(1,:))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!