need help with this summation

1 vue (au cours des 30 derniers jours)
Miguel de la Cruz
Miguel de la Cruz le 23 Fév 2021
Commenté : Walter Roberson le 23 Fév 2021
i cant get the summation correct. is ther any one that can help me or point me in the right dirrection.
clc;
clear;
zeta = 0:.1:2;
fo = [.01;.1;1];
n = 1:2:101;
theta1 = zeros(length(zeta),1);
theta3 = zeros(length(zeta),1);
theta5 = zeros(length(zeta),1);
for i = 1:length(zeta)
for k = 1:length(n)
theta1(i) = theta1(i)+(1/n(k))*exp((-(n(k)^2*pi^2)/4)*fo(1,1))*sin(((n(k)*pi)/2)*zeta(i));
theta3(i) = theta3(i)+(1/n(k))*exp((-(n(k)^2*pi^2)/4)*fo(2,1))*sin(((n(k)*pi)/2)*zeta(i));
theta5(i) = theta5(i)+(1/n(k))*exp((-(n(k)^2*pi^2)/4)*fo(3,1))*sin(((n(k)*pi)/2)*zeta(i));
end
end
theta1 =(4*pi)* theta1;
theta3 =(4*pi)* theta3;
theta5 =(4*pi)* theta5;
plot(zeta,theta1)
hold on
plot(zeta,theta1+theta3)
plot(zeta,theta1+theta3+theta5)

Réponses (1)

Walter Roberson
Walter Roberson le 23 Fév 2021
Modifié(e) : Walter Roberson le 23 Fév 2021
zeta = reshape(linspace(0,2), 1, [], 1); %row
fo = reshape(logspace(-2,0,50), [], 1, 1); %column
n = reshape(1:2:101, 1, 1, []); %pane
t1 = (1./n);
t2 = exp((-(n.^2.*pi.^2)/4) .* fo);
t3 = sin(n .* (pi/2) .* zeta);
temp = t1 .* t2 .* t3;
theta = sum(temp, 3);
surf(zeta, fo, theta, 'edgecolor', 'none')
  3 commentaires
Walter Roberson
Walter Roberson le 23 Fév 2021
zeta = reshape(linspace(0,2), 1, [], 1); %row
fo = reshape([0.01, 0.1, 1], [], 1, 1); %column
n = reshape(1:2:5, 1, 1, []); %pane
t1 = (1./n);
t2 = exp((-(n.^2.*pi.^2)/4) .* fo);
t3 = sin(n .* (pi/2) .* zeta);
temp = t1 .* t2 .* t3;
theta = cumsum(temp, 3);
subplot(3,1,1)
surf(zeta, fo, theta(:,:,1), 'edgecolor', 'none')
title(strjoin(string(n(1:1)), '+'))
subplot(3,1,2)
surf(zeta, fo, theta(:,:,2), 'edgecolor', 'none')
title(strjoin(string(n(1:2)), '+'))
subplot(3,1,3)
surf(zeta, fo, theta(:,:,3), 'edgecolor', 'none')
title(strjoin(string(n(1:3)), '+'))
Walter Roberson
Walter Roberson le 23 Fév 2021
The problem with your graph is that "the first three terms of the series" is not referring to different fo values: it is referring to n = 1, n = 1 + n = 3, n = 1 + n = 3 + n = 5 . And you are supposed to compare at three different fo values. One way of interpreting that would be to use 3 terms * 3 fo = 9 different plots.
Do not add the results for different fo values: only add the results for the different n values.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by