필터 지우기
필터 지우기

Summing with multiple variables

조회 수: 11 (최근 30일)
Tristan Blackledge
Tristan Blackledge 2019년 10월 28일
답변: Asvin Kumar 2019년 10월 31일
I am trying to plot Phi vs x2 but am finding trouble with the summation function. I need to sum for all values of "n" and place the results in a vector for the range x2 so that the vector is the same length as the vector x2 to plot. Would someone be able to show how that is done. Thank you.
D=2;
Ea=0.1;
vEf=0.12;
delta_a=10*pi;
v=0.22;
Phi_o=1;
t=1;
x1=(-delta_a/2:0.1:delta_a/2);
x2=x1';
n=1:2:5;
Bm=n*(pi/delta_a);
lambdam=v*(D*(Bm.^2)+Ea-vEf);
syms x
f=Phi_o.*cos(Bm*x);
Am=2/delta_a.*int(f,-delta_a/2,delta_a/2);
Phi=sum(Am.*cos(Bm.*x2).*exp(-lambdam*t));
plot(x2,Phi)
xlim(-lambdam/2:lambdam/2)
  댓글 수: 1
darova
darova 2019년 10월 28일
Can't use for loop?

댓글을 달려면 로그인하십시오.

답변 (1개)

Asvin Kumar
Asvin Kumar 2019년 10월 31일
Try replacing the appropriate line of code with the following:
Phi=sum(Am.*cos(Bm.*x2).*exp(-lambdam*t),2);
The sum function by default sums along the first array dimension whose size does not equal 1 which in your case is the 1st dimension. Summing along the 2nd dimension should give you output of expected length.
Here’s the documentation for reference: https://www.mathworks.com/help/matlab/ref/sum.html#btv6ok6-1-dim

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by