2 second order differential equations with boundary conditions using bvp4c
Show older comments
problem statement
(d^2 u(x))/〖dx〗^2 =(γu(x))/(1+αu(x))
(d^2 v(x))/〖dx〗^2 =a〖∆v〗^* (dv(x))/dx-2/ε (γu(x))/((1+αu(x)))
at x=0,u=1,v=0
at x=1,du/dx=0,dv/dx=0
α=0.001,γ=100 ,epsilon=1,〖∆v〗^*=0.1 a=[0,10,100,500,1000] plot v verses x
Matlab Code:
alpha = 0.001;
gamma = 100;
epsilon = 1;
delta_v = 0.1;
a_values = [0, 10, 100, 500, 1000];
for i = 1:length(a_values)
%% options = bvpset('RelTol', 1e-6, 'AbsTol', 1e-6); % Set options
sol = bvp4c(@equations, @boundary_conditions, initial_guess);
x = linspace(0, 1, 100);
y = deval(sol, x);
plot(x, y(2, :)); % Plot x versus v
hold on;
xspan = [0, 1]; % Define the interval
initial_guess = [1, 0, 0, 0]; % Initial guess for u, v, du/dx, dv/dx
legend('a = 0', 'a = 10', 'a = 100', 'a = 500', 'a = 1000');
xlabel('x');
ylabel('v(x)');
title('Plot of x versus v(x)');
end
function res = boundary_conditions(ya, yb)
res = [ya(1) - 1; ya(2); yb(3); yb(4)]; % Boundary conditions
end
function dydx = equations(x, y)
u = y(1);
v = y(2);
dydx = zeros(4, 1);
dydx(1) = y(3); % du/dx
dydx(2) = y(4); % dv/dx
dydx(3) = (gamma * y(1)) / (1 + alpha * y(1));
dydx(4) = a * delta_v_star * y(4) - (2 / epsilon) * (gamma * y(1)) / (1 + alpha * y(1));
end
getting error Unrecognized function or variable 'initial_guess'.
Answers (1)
Almost the same code as in the preceeding problem:
% Parameters
alpha = 0.001;
gamma = 100;
epsilon = 1;
delta_v = 0.1;
a=[0,10,100,500,1000];
hold on
for i = 1:numel(a)
fcn = @(x,y)[y(3);y(4);(gamma*y(1))/(1+alpha*y(1));a(i)*delta_v*y(4)-(2/epsilon)*(gamma*y(1))/(1+alpha*y(1));];
bc = @(ya,yb)[ya(1)-1;ya(2);yb(3);yb(4)];
guess = @(x)[1;0;0;0];
xmesh = linspace(0,1,20);
solinit = bvpinit(xmesh, guess);
sol = bvp4c(fcn, bc, solinit);
plot(sol.x,sol.y(2,:))
end
hold off
grid on
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!