Summing over indices using symsum
古いコメントを表示
I am trying to calculate electric field
at position
due to charges
The equation is
.
.If I can figure out how to for example just get this sum
, I would be able to figure out the equation for the electric field. I tried
u=symunit;
syms k
e0=8.854E-12*(u.s)^4*(u.A)^2/((u.kg)*(u.m)^3);
Q1=10E-9*(u.C);
Q2=15-9*(u.C);
Q3=7E-9*(u.C);
r1=[1 4 2]*1E-3*(u.m);
r2=[-2 0 5]*1E-3*(u.m);
r3=[-1 -2 3]*1E-3*(u.m);
r=[5 5 5]*1E-3*(u.m);
Q=symsum(Qk,k,1,3)
That obviously didn't work. Is there a way to make it work with 'symsum'?
5 件のコメント
Torsten
2023 年 3 月 17 日
Why do you use symbolic variables if all variables involved have numeric values ?
RH
2023 年 3 月 17 日
u=symunit;
syms k
e0 = sym(8854)*sym(10)^(-15)*(u.s)^4*(u.A)^2/((u.kg)*(u.m)^3);
Q1 = sym(10)*sym(10)^(-9)*(u.C);
Q2 = sym(15)*sym(10)^(-9)*(u.C);
Q3 = sym(7)*sym(10)^(-9)*(u.C);
r1=[1 4 2]*sym(10)^(-3)*(u.m);
r2=[-2 0 5]*sym(10)^(-3)*(u.m);
r3=[-1 -2 3]*sym(10)^(-3)*(u.m);
r=[5 5 5]*sym(10)^(-3)*(u.m);
Qs = [Q1, Q2, Q3];
Q = sum(Qs)
Walter Roberson
2023 年 3 月 17 日
If you have somehow created a list of numbered variables that is too long to make it practical to put them into a list by name, then what you should do is...
Not create a list of numbered variables that is too long to make it practical to put them into a list by name.
Note that the sum isn't just over Q, but rk as well
(Without syms and symunit but values according SI units)
e0=8.854E-12;
Q=[10E-9 15E-9 7E-9];
R=[1 4 2;-2 0 5;-1 -2 3]*1E-3;
r=[5 5 5]*1E-3;
r0=vecnorm(r-R,2,2).^3;
out=sum(Q.*(r-R)./(4*pi*e0*r0),1)
採用された回答
その他の回答 (1 件)
Walter Roberson
2023 年 3 月 17 日
1 投票
You cannot use a symbolic variable as an index.
I think it is unlikely that it will ever be supported to use symbolic variables as indices.
Create the definite values and sum() the definite values.
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
