Error in Bvp4c

11 views (last 30 days)
Priya M
Priya M on 23 Oct 2021
Answered: MOSLI KARIM on 27 Nov 2023
I'm trying to run the following bvp4c MATLAB code, but keep running into an error:
please anyone find out my mistakes and correct me..
Thank you.

Accepted Answer

Jan
Jan on 23 Oct 2021
You define the variable beta on top of the code, but this does not mean, that it is known in all subfunctions. Pr, gamma and lam are not known inside also.
Either define the constants, where they are needed, or provide them using an anonymous function:
for gamma=0.0:0.25:1
sol = bvpinit(linspace(0,5,50),[0 0 0 0 0 0 0]);
fcn = @(t,y) bvpexam1(t, y, beta, gamma, lam, Pr);
sol1 = bvp4c(fcn, @bcexam1,sol);
...
end
function ysol = bvpexam1(t, y, beta, gamma, lam, Pr)
...
end
  5 Comments
Jan
Jan on 27 Oct 2021
Edited: Jan on 27 Oct 2021
f =@(x,y)[y(2);
...
(1/(1+E*y(6)-Pr*gamma*y(1)^2))*(-E*y(7)^2-Pr*y(1)*y(7)+Pr*gamma*y(1)*y(2)*y(7))];
% ^
There is a missing closing square bracket in your code. After adding it I get a result.
Priya M
Priya M on 28 Oct 2021
Thanx a lot sir....

Sign in to comment.

More Answers (1)

MOSLI KARIM
MOSLI KARIM on 27 Nov 2023
this code works function d
Pr=0.72;
beta=0.5;
lam=0.2;
E=0.5;
for gamma=0.0:0.25:1
sol = bvpinit(linspace(0,5,50),[0 0 0 0 0 0 0]);
sol1 = bvp4c(@bvpexam1, @bcexam1,sol);
x1 = sol1.x;
y1 = sol1.y;
figure (1)
plot(x1, y1(2,:));
hold on
figure (2)
plot(x1, y1(6,:));
hold on
z = y1(3,1);
p = y1(7,1)'
figure(3)
plot(gamma,y1(7,1),'-bo')
hold on
end
function res = bcexam1(y0, yinf)
res=[y0(1)-0;y0(2)-1;y0(4)-0;y0(6)-1;yinf(2)-0;yinf(4)-0;yinf(6)-0];
end
function ysol = bvpexam1(~,y)
yy1 = (1/(1-beta*y(1)^2))*(-y(1)*y(3)+y(2)^2-2*lam*(y(4)-beta*y(1)*y(5))-2*beta*y(1)*y(2)*y(3));
yy2 = (1/(1-beta*y(1)^2))*(-y(1)*y(5)+y(2)*y(4)+2*lam*(y(2)+beta*(y(2)^2-y(1)*y(3)+y(4)))-2*beta*y(1)*y(2)*y(5));
yy3 = (1/(1+E*y(6)-Pr*gamma*y(1)^2))*(-E*y(7)^2-Pr*y(1)*y(7)+Pr*gamma*y(1)*y(2)*y(7));
ysol = [y(2);y(3);yy1;y(5);yy2;y(7);yy3];
end

Community Treasure Hunt

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

Start Hunting!