Loop for bvp4c function with an unknown parameter

21 ビュー (過去 30 日間)
Ramin Rabani
Ramin Rabani 2017 年 12 月 7 日
編集済み: MINATI 2020 年 5 月 24 日
I tried to solve sixth order differential equation using bvp4c with an unknown parameter “S” and one variable parameter “k”. I have written a subroutine as a bvp4c and a main function for “k”.
The main code is written as follows:
function [] = main()
kk=0.5 ;
for i=1:60
k=kk;
valuePresentstudy = Surfactant(k);
kk=kk+0.1;
end
end
The bvp4c subroutine is written as follows:
function valuePresentstudy = Surfactant(k)
options = bvpset('NMax',100000);
S=0.28;
solinit = bvpinit(linspace(0,1,100),[0.1 0 0 0 0 0],S);
sol = bvp4c(@(x,y)fourode(x,y,k),@(ya,yb)fourbc(ya,yb,k),solinit,options);
save hatimsol.mat sol
x = linspace(0,1);
y = deval(sol,x);
valuePresentstudy=y;
%
function dydx = fourode(x,y,S,k)
Pr=10;
dydx = [ y(2); y(3); y(4); -(k^4+(S/Pr)*k^2)*y(1)+(2*(k^2)+(S/Pr))*y(3); y(6); (k^2+S)*y(5)-y(1)];
%
function res = fourbc(ya,yb,S,k)
e=0;
res = [ ya(1); ya(2); ya(5); yb(1); yb(6)+e*k*yb(5); yb(5)-1; yb(6)];
The error is given as:
Error using Surfactant>@(x,y)fourode(x,y,k)
Too many input arguments.
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in Surfactant (line 5)
sol = bvp4c(@(x,y)fourode(x,y,k),@(ya,yb)fourbc(ya,yb,k),solinit,options);
Error in MainPresentSurfactant (line 6)
valuePresentstudy = Surfactant(k);
Could you please tell me where my mistake is?
Thanks in advance for your help.

採用された回答

Torsten
Torsten 2017 年 12 月 7 日
Maybe
sol = bvp4c(@(x,y,S)fourode(x,y,S,k),@(ya,yb,S)fourbc(ya,yb,S,k),solinit,options);
Otherwise pass k to fourode and fourbc as global.
Best wishes
Torsten.
  1 件のコメント
Ramin Rabani
Ramin Rabani 2017 年 12 月 7 日
編集済み: Ramin Rabani 2017 年 12 月 7 日
Thank you for your reply. it Worked for me. Thanks a lot for your help

サインインしてコメントする。

その他の回答 (2 件)

Torsten
Torsten 2017 年 12 月 7 日
function [] = main()
kk=0.5 ;
for i=1:60
k=kk;
valuePresentstudy = Surfactant(k);
kk=kk+0.1;
end
end
function valuePresentstudy = Surfactant(k)
global kk
kk = k;
options = bvpset('NMax',100000);
S=0.28;
solinit = bvpinit(linspace(0,1,100),[0.1 0 0 0 0 0],S);
sol = bvp4c(@fourode,@fourbc,solinit,options);
save hatimsol.mat sol
x = linspace(0,1);
y = deval(sol,x);
valuePresentstudy=y;
%
function dydx = fourode(x,y,S)
global kk
Pr=10;
dydx = [ y(2); y(3); y(4); -(kk^4+(S/Pr)*kk^2)*y(1)+(2*(kk^2)+(S/Pr))*y(3); y(6); (kk^2+S)*y(5)-y(1)];
%
function res = fourbc(ya,yb,S)
global kk
e=0;
res = [ ya(1); ya(2); ya(5); yb(1); yb(6)+e*kk*yb(5); yb(5)-1; yb(6)];
Best wishes
Torsten.
  1 件のコメント
Tanya Sharma
Tanya Sharma 2019 年 10 月 7 日
Hi Torsten, I am working on a similar kind of problem where S is unknown eigenvalue.
Can I evaluate eigenvalues S using bvp4c?

サインインしてコメントする。


Akmaral Pussurmanova
Akmaral Pussurmanova 2020 年 5 月 6 日
I don't know where is a mistake( Can you help me?
function dxdt = mat4ode(t,x,mu) % equation being solved
alfa = 0;
dxdt = [x(2)
-x(1)+0.1*(alfa*cos(2*t)*x(1)+x(1)^3)+mu*sin(2*t)+(1-pi^2)*sin(pi*t)+1-0.1*((sin(pi*t)+1)^3)-2*sin(2*t)];
end
%-------------------------------------------
function res = mat4bc(xa,xb,mu) % boundary conditions
res = [xa(1)-1
xb(1)-1
xa(2)-xb(2)];
end
%-------------------------------------------
function yinit = mat4init(t) % initial guess function
yinit = [sin(pi*t)+1
pi*cos(pi*t)
];
end
mu=2;
solinit = bvpinit(linspace(0,2,20),@mat4init,mu);
sol = bvp4c(@mat4ode, @mat4bc, solinit);
fprintf('Fourth eigenvalue is approximately %7.3f.\n',...
sol.parameters)
xint = linspace(0,2);
Sxint = deval(sol,xint);
plot(xint,Sxint)
axis([0 2 -4 4])
title('Eigenfunction of Mathieu''s Equation.')
xlabel('x')
ylabel('y')
legend('y','y''')
  1 件のコメント
MINATI
MINATI 2020 年 5 月 24 日
編集済み: MINATI 2020 年 5 月 24 日
Dear
Akmaral
Post ur doubt in another question page and mail me the link @
minatipatra456@gmail.com

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBoundary Value Problems についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by