필터 지우기
필터 지우기

Problem with solving an ODE

조회 수: 1 (최근 30일)
Della
Della 2023년 5월 17일
답변: Torsten 2023년 5월 17일
Hello,
When I run the code below, I get an error because the initial condition for y is dependent on Dy. I've seen this case (boundary conditions depend on first derivatives) in a few papers, but I'm not sure how to solve it. Could someone please help me with this?
syms y Dy D2y x Y
y0=(5+Dy*2)/0.49;
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)-y0;yb(2)-1];
xmesh = linspace(1e-3,4,10);
solinit = bvpinit(xmesh, [1 1]);
sol = bvp4c(odefcn,bcfcn,solinit);
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.

Error in bvp4c>colloc_RHS (line 543)
Phi(1:nBCs) = Gbc(y(:,Lidx),y(:,Ridx),ExtraArgs{1:nExtraArgs});

Error in bvp4c (line 182)
[RHS,yp,Fmid,NF] = colloc_RHS(n,x,Y,ode,bc,npar,xyVectorized,mbcidx,nExtraArgs,ExtraArgs);

Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
plot(sol.x,sol.x.*sol.y(1,:))

채택된 답변

Torsten
Torsten 2023년 5월 17일
Use
bcfcn = @(ya,yb)[ya(1)-(5+ya(2)*2)/0.49;yb(2)-1];
instead of
bcfcn = @(ya,yb)[ya(1)-y0;yb(2)-1];
in your code.

추가 답변 (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