help me what is the error in the code not able to plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
% current density equation j=dv/dx=0 at x=0
alpha = 0.1;
gamma =[1,50,100,500,1000];
epsilon = 1;
a=1000;
%% u=y(1)
%% v=y(2)
%% du/dx=dy(1)/dx=y(3)
%%d^2u/dx^2=dy(3)/dx=gamma*y(1)/(1+alpha*y(1)
%% dv/dx=dy(2)/dx=y(4)
%% d^2v/dx^2=dy(4)/dx=a*delta_v*y(4)-(2/epsilon)*gamma*y(1)/(1+alpha*y(1)
figure
hold on;
for i = 1:numel(gamma)
fcn = @(x, y) [y(3); y(4); (gamma(i) * y(1)) / (1 + alpha * y(1)); a * sol.y(2, x) * y(4) - (2 / epsilon) * (gamma(i) * 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, [], gamma(i));
voltage_drop_values = sol.y(2, :);
current_density_values = sol.y(4, :);
plot(voltage_drop_values, current_density_values);
end
xlabel('Normalized voltage drop across the cell (delta_v*)');
ylabel('Normalized current density at the boundary condition for dv/dx at x=0');
title('Plot of normalized current density at the boundary condition for dv/dx at x=0 versus gamma');
legend('\gamma = 1', '\gamma = 50', '\gamma = 100', '\gamma = 500', '\gamma = 1000');
hold off;
grid on;
xlim([1e-4, 1e2]);
ylim([0, 70]);
Antworten (1)
Ishu
am 9 Mai 2024
Hi Anitha,
Given your clarification about the error, it is occurring with the "bvp4c" function due to "Too many input arguments".
The "bvp4c" function in MATLAB is used to solve Boundary Value Problems (BVP) for Ordinary Differential Equations (ODE). Its basic usage is as follows:
sol = bvp4c(odefun, bcfun, solinit, options);
Based on your description, there was an attempt to pass five arguments to "bvp4c", which exceeds its limit of four arguments, thus leading to the "Too many input arguments" error. To correct this, ensure you are using "bvp4c" correctly by adjusting the call to include only the necessary arguments.
If you have additional parameters that need to be passed into your function, you need to ensure these are encapsulated within those function definitions, possibly using anonymous functions or nested functions that have access to the additional parameters.
sol = bvp4c(fcn, bc, solinit);
The usage of "sol.y(2,x)" in "fcn" is incorrect because "x" is not an index; it will result in an error. To correct this, you can use "deval" instead.
deval(sol, x, 2); %Replace with sol.y(2,x);
You can refer below documentations for more information:
Hope it helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Boundary Value Problems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!