필터 지우기
필터 지우기

How can I plot an equation that includes sigma?

조회 수: 1 (최근 30일)
Sojung Park
Sojung Park 2023년 5월 4일
댓글: Star Strider 2023년 5월 4일
I'm trying to plot the eqution above and I used symsum but the code below plots nothing. How can I fix this?(N_k is the )
clear
clc
%Parameter
L_c=0.05;%m
zeta=1/29;
V_avg=11.2;%m/s
St=0.29;
d=0.025;%m
Cir_0=d/(2*St);%m
Cir_cr=Cir_0*V_avg;
B_0=0.006;%s/m^2
c=700;%m/s
P_avg=101325;%Pa
gamma=1.4;
omega=250;
omega_d=sqrt(4*omega^2-zeta^2);
B=B_0*Cir_cr*omega*cos(omega*L_c/c);
%calculation
t_upTo=1.5;
t_step=0.01;
t_j=0.04;
for t=0:t_step:t_upTo
N_k=floor(t/t_j);
syms k
total=B/omega_d.*symsum(exp(-(zeta/2).*(t-t_j*k)).*(-zeta.*sin(omega_d/2.*(t-t_j*k))+omega_d.*cos(omega_d/2.*(t-t_j*k))),k,0,N_k);
plot(t,total)
end

채택된 답변

Star Strider
Star Strider 2023년 5월 4일
I changed ‘t’ to ‘tv’ and then created ‘t’ in each iteration as ‘tv(k1)’ to produce a vector for ‘total’ that is then plotted at the end.
Try this —
%Parameter
L_c=0.05;%m
zeta=1/29;
V_avg=11.2;%m/s
St=0.29;
d=0.025;%m
Cir_0=d/(2*St);%m
Cir_cr=Cir_0*V_avg;
B_0=0.006;%s/m^2
c=700;%m/s
P_avg=101325;%Pa
gamma=1.4;
omega=250;
omega_d=sqrt(4*omega^2-zeta^2);
B=B_0*Cir_cr*omega*cos(omega*L_c/c);
%calculation
t_upTo=1.5;
t_step=0.01;
t_j=0.04;
tv=0:t_step:t_upTo;
for k1 = 1:numel(tv);
t = tv(k1);
N_k=floor(t/t_j);
syms k
total = B/omega_d.*symsum(exp(-(zeta/2).*(t-t_j*k)).*(-zeta.*sin(omega_d/2.*(t-t_j*k))+omega_d.*cos(omega_d/2.*(t-t_j*k))),k,0,N_k);
totalv(k1) = double(total);
end
figure
plot(tv,totalv)
grid
xlabel('t')
ylabel('total')
The original plot call did not work first because ‘total’ is a symbolic variable, not a numeric variable. Even if it had been a numeric variable, plot would not have plotted anythinbg because it only plots lines between two or more defined points, not single points, unless it was told to plot with a marker. This slight variation on your original code solves both of those problems.
.
  댓글 수: 2
Sojung Park
Sojung Park 2023년 5월 4일
I didn't know about the difference of symbolic and numeric variable. This was very helpful. Thanks a lot!
Star Strider
Star Strider 2023년 5월 4일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by