How to solve it for a scalar output?

7 ビュー (過去 30 日間)
Rahul
Rahul 2024 年 9 月 6 日
コメント済み: Torsten 2024 年 9 月 6 日
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

回答 (1 件)

Torsten
Torsten 2024 年 9 月 6 日
移動済み: Torsten 2024 年 9 月 6 日
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 件のコメント
Walter Roberson
Walter Roberson 2024 年 9 月 6 日
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 2024 年 9 月 6 日
But I wonder if it make sense or not?
I wonder how I could tell.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by