Loop for bvp4c function with an unknown parameter

조회 수: 20 (최근 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 CenterFile Exchange에서 Boundary Value Problems에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by