Loop for bvp4c function with an unknown parameter

9 Ansichten (letzte 30 Tage)
Ramin Rabani
Ramin Rabani am 7 Dez. 2017
Bearbeitet: MINATI am 24 Mai 2020
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.

Akzeptierte Antwort

Torsten
Torsten am 7 Dez. 2017
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 Kommentar
Ramin Rabani
Ramin Rabani am 7 Dez. 2017
Bearbeitet: Ramin Rabani am 7 Dez. 2017
Thank you for your reply. it Worked for me. Thanks a lot for your help

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Torsten
Torsten am 7 Dez. 2017
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 Kommentar
Tanya Sharma
Tanya Sharma am 7 Okt. 2019
Hi Torsten, I am working on a similar kind of problem where S is unknown eigenvalue.
Can I evaluate eigenvalues S using bvp4c?

Melden Sie sich an, um zu kommentieren.


Akmaral Pussurmanova
Akmaral Pussurmanova am 6 Mai 2020
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 Kommentar
MINATI
MINATI am 24 Mai 2020
Bearbeitet: MINATI am 24 Mai 2020
Dear
Akmaral
Post ur doubt in another question page and mail me the link @
minatipatra456@gmail.com

Melden Sie sich an, um zu kommentieren.

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by