Loop for bvp4c function with an unknown parameter

2 次查看(过去 30 天)
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.

更多回答(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
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