solve bvp using bvp4c
Mostra commenti meno recenti
function ModifiedHNF()
global C1
global C2
format long
solinit=bvpinit(linspace(0,4,3),[0,0,0,0,0]);
sol=bvp4c(@deriv,@bcs,solinit);
x = linspace(0,4);
y = deval(sol,x);
% plot(sol.x,sol.y(1,:),'r-');
plot(x,y(1,:),'r-');
end
function dydx = deriv(~,y)
Pr=6.2;
phi_1=[0 0.10 0.50];
phi_2=[0 0.01 0.10];
C1=(1-phi_1).*(1-phi_2)+(((1-phi_2).*(phi_1.*3970)+(phi_2.*8933))/997.1);
C2=(1-phi_1).*(1-phi_2)+((1-phi_2).*phi_1.*(3970*765)+phi_2.*(8933*385))/(997.1*4179);
knf=(40+(2.*0.613)-(2.*phi_1).*(0.613-40)).*(0.613)/(40+(2.*0.613)+(phi_1)*(0.613-40));
khnf=(400+(2.*knf)-(2.*phi_2).*(knf-400)).*(knf)/(400+(2.*knf)+(phi_2).*(knf-400));
dydx = [y(2);
y(3);
-C1.*(y(1).*y(3)-y(2).*y(2)).*(1-phi_1).^(2.5).*(1-phi_2).^(2.5);
y(5);
-C2.*Pr.*(y(1).*y(5).*0.613)/khnf];
end
function res = bcs(ya,yb)
S=0;
Lambda=1;
Bi=[0.5 1 20];
res = [ ya(1)-S;
ya(2)- Lambda;
ya(5)+((0.613/khnf)*Bi*(1-ya(4)));
yb(2);
yb(4)];
end
this is the code to solve bvp using bvp4c where i have 5 odes. however, it shows an error in command window.
it says Error in ModifiedHNF (line 7)
sol=bvp4c(@deriv,@bcs,solinit);
1 Commento
MOSLI KARIM
il 7 Nov 2023
Here is the correction to your code
function ModifiedHNF()
global Pr phi_1 phi_2 C1 C2 knf khnf Lambda S Bi
Pr = 6.2;
S = 0;
Lambda = 1;
Bi = 0.5;
% Cell array pour stocker les noms de couleur
colors = {'r', 'g', 'b', 'c', 'm', 'k'};
% Cell array pour stocker les noms de la légende
legend_names = {};
for phi_1 = [0 0.10 0.50]
for phi_2 = [0 0.01 0.10]
C1 = (1 - phi_1) * (1 - phi_2) + (((1 - phi_2) * (phi_1 * 3970) + (phi_2 * 8933)) / 997.1);
C2 = (1 - phi_1) * (1 - phi_2) + ((1 - phi_2) * phi_1 * (3970 * 765) + phi_2 * (8933 * 385)) / (997.1 * 4179);
knf = (40 + (2 * 0.613) - (2 * phi_1) * (0.613 - 40)) * (0.613) / (40 + (2 * 0.613) + (phi_1) * (0.613 - 40));
khnf = (400 + (2 * knf) - (2 * phi_2) * (knf - 400)) * (knf) / (400 + (2 * knf) + (phi_2) * (knf - 400));
solinit = bvpinit(linspace(0, 4, 3), [0, 0, 0, 0, 0]);
sol = bvp4c(@deriv, @bcs, solinit);
x = linspace(0, 4);
y = deval(sol, x);
figure(1)
hold on
% Utiliser le modulo (%) pour garantir que le compteur reste dans la plage des indices valides
color_index = mod(length(legend_names), length(colors)) + 1;
plot(x, y(1, :), colors{color_index});
% Ajouter le nom de la combinaison de phi_1 et phi_2 à la légende
legend_names{end+1} = ['\phi_1=' num2str(phi_1) ', \phi_2=' num2str(phi_2)];
end
end
% Ajouter la légende
legend(legend_names);
function dydx = deriv(~, y)
dydx = [y(2);
y(3);
-C1 * (y(1) * y(3) - y(2) * y(2)) * (1 - phi_1)^(2.5) * (1 - phi_2)^(2.5);
y(5);
-C2 * Pr * (y(1) * y(5) * 0.613) / khnf];
end
function res = bcs(ya, yb)
res = [ya(1) - S;
ya(2) - Lambda;
ya(5) + ((0.613 / khnf) * Bi * (1 - ya(4)));
yb(2);
yb(4)];
end
end
Risposte (0)
Categorie
Scopri di più su Boundary Value Problems in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!