How to solve it for a scalar output?

7 views (last 30 days)
Rahul
Rahul on 6 Sep 2024
Commented: Torsten on 6 Sep 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

Answers (1)

Torsten
Torsten on 6 Sep 2024
Moved: Torsten on 6 Sep 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 Comments
Walter Roberson
Walter Roberson on 6 Sep 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 on 6 Sep 2024
But I wonder if it make sense or not?
I wonder how I could tell.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!