필터 지우기
필터 지우기

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