Unable to solve the collocation equations -- a singular Jacobian encountered.
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Torsten
on 8 May 2023
Edited: Torsten
on 8 May 2023
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 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!