Borrar filtros
Borrar filtros

Not enough input arguments. Error in odefun (line 2) y1 = y(1); Error in bvp4c (line 5) sol =bvp4c(ode​fun,bcfun,​solinit);

8 visualizaciones (últimos 30 días)
function dydx = odefun(y,x) % equation to solve
y1 = y(1);
y2= y(2);
dy1_dx = y(2);
dy2_dx = [U*y2+K*y1/D];
dy_dx = [dy_dx; dy2_dx];
end
function bcfun=bvp_bc(ya,yb)
bc=[ya(1)-3*yb(1)-2];
guess =[2;1];
xmesh = linspace(0,1,5);
solinit = bvpinit(xmesh,guess);
sol =bvp4c(odefun,bcfun,solinit);
plot(sol.x,sol.y(1,:),'--o');
title('chlorine decay')
xlabel('pipe length(m)');
ylabel('Concentration (mg/L)');
function dydx = ode(x,y)
D=0.1; % m2/s
U=1; % m/s
K = 1*10^-6; % 1/s
dydx = [y(2)*(U*y(2)+K*y(1))/D];
end
function res = bc(ya,yb)
res = [ya(1)-3 yb(1)-2];
end
I need to plot C vs x using Matlab's BVP4C

Respuestas (2)

Walter Roberson
Walter Roberson el 19 de Mzo. de 2022
As we told you in one of your other questions, the first two parameters to bvp4c need to be function handles, not function names. As in bvp4c(@odefun, @bcfun, solinit)
  10 comentarios
Naveen Krish
Naveen Krish el 19 de Mzo. de 2022
Editada: Walter Roberson el 21 de Mzo. de 2022
Error: File: bp4.m Line: 21 Column: 1
The function "bc" was closed with an 'end', but at least one other function definition was not. To avoid confusion when using
nested functions, it is illegal to use both conventions in the same file.
function dydx = odefun(y,x) % equation to solve
y1 = y(1);
y2= y(2);
dy1_dx = y(2);
dy2_dx = [U*y2+K*y1/D];
dy_dx = [dy_dx; dy2_dx];
end
function bcfun=bvp_bc(ya,yb)
bc=[ya(1)-3*yb(1)-2];
guess =[2;1];
xmesh = linspace(0,1,5);
solinit = bvpinit(xmesh,guess);
sol =bvp4c(@odefun,@bcfun,solinit);
which -all bvp4c
plot(sol.x,sol.y(1,:),'--o');
title('chlorine decay')
xlabel('pipe length(m)');
ylabel('Concentration (mg/L)');
function dydx = ode(x,y)
D=0.1; % m2/s
U=1; % m/s
K = 1*10^-6; % 1/s
dydx = [y(2)*(U*y(2)+K*y(1))/D];
end
function res = bc(ya,yb)
res = [ya(1)-3 yb(1)-2];
end
Walter Roberson
Walter Roberson el 21 de Mzo. de 2022
guess =[2;1];
xmesh = linspace(0,1,5);
solinit = bvpinit(xmesh,guess);
sol = bvp4c(@odefun,@bcfun,solinit);
plot(sol.x,sol.y(1,:),'--o');
title('chlorine decay')
xlabel('pipe length(m)');
ylabel('Concentration (mg/L)');
function dydx = odefun(y,x) % equation to solve
y1 = y(1);
y2= y(2);
dy1_dx = y(2);
dy2_dx = [U*y2+K*y1/D];
dy_dx = [dy_dx; dy2_dx];
end
function res = bcfun(ya,yb)
res = [ya(1)-3
yb(1)-2];
end

Iniciar sesión para comentar.


MOSLI KARIM
MOSLI KARIM el 17 de Dic. de 2022
function ANSWER_MATHWORKII
D=0.1; % m2/s
U=1; % m/s
K = 1*10^-6;% equation to solve
guess =[2;1];
xmesh = linspace(0,1,5);
solinit = bvpinit(xmesh,guess);
sol =bvp4c(@fct,@bc,solinit);
plot(sol.x,sol.y(1,:),'--o');
title('chlorine decay')
xlabel('pipe length(m)');
ylabel('Concentration (mg/L)');
% dydx = [y(2) ; U*y(2)+(K*y(1))/D];
function yp=fct(x,y)
yp=[y(2);U*y(2)+(K*y(1))/D ];
end
function res = bc(ya,yb)
res = [ya(1)-3 ;yb(1)-2];
end
end

Categorías

Más información sobre System on Chip (SoC) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by