How to solve it for a scalar output?

1 visualización (últimos 30 días)
Rahul
Rahul el 6 de Sept. de 2024
Comentada: Torsten el 6 de Sept. de 2024
Hi,
I'm trying to find the electron current using the relation J=sigma[E+uxB]
for which my code gives an error
Unable to perform assignment because the left and right sides have a different number of elements.
Error in pde2fshear_fisher_new>pdex2pde (line 738)
je(STEP_x)=sig*(DuDx(1)+cross(ue,Bt));
which I'm unable to debug it
my code is as below
function [c,f,s] = pdex2pde(x,t,u,DuDx)
c = [1;1;1];STEP_x=2; zone=1;B0=4617;a=.9;R0=6; ue = [1.0;0;0];
xmin = 0;xmax = 1;xstep = 100; sig=1;
X = linspace(xmin,xmax,xstep-1);
if STEP_x==1
Btx=B0/(R0/a+zone*X(STEP_x));
Bt=[Btx;0;0];
je(STEP_x)= sig*(DuDx(1)+cross(ue,Bt));
elseif STEP_x > 1 && STEP_x <= 5
Btx=B0/(R0/a+zone*X(STEP_x));
disp(Btx);
Bt=[Btx;0;0];
je(STEP_x)=sig*(DuDx(1)+cross(ue,Bt));
else
Btx=B0/(R0/a+zone*X(STEP_x));
Bt=[Btx;0;0];
je(STEP_x)=sig*(DuDx(1)+cross(ue,Bt));
end
end

Respuestas (1)

Torsten
Torsten el 6 de Sept. de 2024
Movida: Torsten el 6 de Sept. de 2024
cross(...) usually gives a vector as result, but je(STEP_x) is a scalar. You can't assign a vector to a scalar.
a(1) = cross([1 2 3],[4 5 6])
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
  3 comentarios
Walter Roberson
Walter Roberson el 6 de Sept. de 2024
je(STEP_x) = sig*(DuDx(1) + norm(cross(ue,Bt)));
Question:
What is the difference between your three branches? The only difference I can see is that you have an extra disp(Btx); in one of the branches.
Torsten
Torsten el 6 de Sept. de 2024
But I wonder if it make sense or not?
I wonder how I could tell.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by