Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

I want to solve a multi point boundary condition differential equation. I keep getting error on my Bvp4c line, I tried debugging it, but could resolve the error.

1 visualización (últimos 30 días)
function rhs = bvp_rhs(x,T)
rhs=[T(2); ((v/(2*a))^2)* T(1)];
function bc=bvp_bc(Tl,Tm,Tr)
bc=[Tl(1);Tm(21);(1/k)*e^(vx/(2*a))*(Tr(2)(200)+(Tr(1)(200)(v/(2*a))))];
x = linspace(1,200);
a = 0.25;
v=20;
k=45;
q=0.005;
solinit=bvpinit(linspace(1,200),[0,0]);
sol = bvp4c(@bvp_rhs,@bvp_bc,solinit);
BS=deval(sol,x);
plot(x,BS);

Respuestas (1)

Stephan
Stephan el 22 de Oct. de 2018
Hi,
there are several Problems in your code:
bc=[Tl(1);Tm(21);(1/k)*exp(vx/(2*a))*(Tr(2)(200)+(Tr(1)(200)(v/(2*a))))];
produces error because:
Tr(2)(200)+(Tr(1)(200)(v/(2*a)))
is not a valid Matlab syntax, maybe you mean:
Tr(2) * 200 + (Tr(1) * 200 * (v/(2*a))) or
Tr(2) + 200 + (Tr(1) + 200 + (v/(2*a)))
however, this has to be fixed.
--------------
Next Problem - If you want to express
e^x
in Matlab, the syntax is:
exp(x)
So if you fix this a valid line of Matlab code could look like this:
bc=[Tl(1);Tm(21);(1/k)*exp(vx/(2*a))*(Tr(2)*(200)+(Tr(1)*(200)*(v/(2*a))))];
But this has to be checked by you, because i made just a guess / an example.
------------
Next problem - When you fixed your equation to something valid, the variables v,a, and k are unknown in the functions. Fix this with a nested structure like this:
function solve_bvp
x = linspace(1,200);
a = 0.25;
v=20;
k=45;
q=0.005;
solinit=bvpinit(linspace(1,200),[0,0]);
sol = bvp4c(@bvp_rhs,@bvp_bc,solinit);
BS=deval(sol,x);
plot(x,BS);
function rhs = bvp_rhs(x,T)
rhs=[T(2); ((v/(2*a))^2)* T(1)];
end
function bc=bvp_bc(Tl,Tm,Tr)
bc=[Tl(1);Tm(21);(1/k)*exp(vx/(2*a))*(Tr(2)*(200)+(Tr(1)*(200)*(v/(2*a))))];
end
end
---------------
Next problem - Index exceeds array bounds:
Sure that
Tm(21)
can be correct? It should be Tm(1) or Tm(2) i guess.
----------------
Next problem - Undefined function or variable 'vx'. I guess
exp(vx/(2*a))
should be
exp(v*x/(2*a))
then this error is fixed - Or is there a missing variable vx?
-----------------
There are more errors in this code - i stopped debugging, because i think you should fix this so far, read about Matlab fundamentals and come back if you have done so far.
Best regards
Stephan

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by