Clear Filters
Clear Filters

How can I plot an equation that includes sigma?

1 view (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 4 May 2023
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 Comments
Sojung Park
Sojung Park on 4 May 2023
I didn't know about the difference of symbolic and numeric variable. This was very helpful. Thanks a lot!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!