フィルターのクリア

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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by