Error in Bvp4c

1 次查看(过去 30 天)
Priya M
Priya M 2021-10-23
回答: MOSLI KARIM 2023-11-27
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.

采纳的回答

Jan
Jan 2021-10-23
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 个评论
Jan
Jan 2021-10-27
编辑:Jan 2021-10-27
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 2021-10-28
Thanx a lot sir....

请先登录,再进行评论。

更多回答(1 个)

MOSLI KARIM
MOSLI KARIM 2023-11-27
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

类别

Help CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by