Unable to solve the collocation equations -- a singular Jacobian encountered.

1 次查看(过去 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,:))

采纳的回答

Torsten
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)
ode1 = 
ode2 = matlabFunction(ode1(1),'Vars',{x,[y Dy]})
ode2 = function_handle with value:
@(x,in2)(in2(:,1).*(sqrt(1.0./in2(:,1))-in2(:,2)./in2(:,1)))./x
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,:))
Warning: Imaginary parts of complex X and/or Y arguments ignored.

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by