Effacer les filtres
Effacer les filtres

Plotting a summation with two variables

4 vues (au cours des 30 derniers jours)
Alice K
Alice K le 6 Avr 2023
Commenté : Alice K le 6 Avr 2023
Hi All,
I need to plot a summation but I keep getting a blank plot,
Any help you can give would be great.
Here is my summation:
Here is the code I have tried:
t = linspace(0,0.01,1);
x = linspace(0,0.01,1);
n = 100;
for k = 0:1:n
y = (6/(pi+6*k*pi))*sin(k*x)*exp((-(pi/6+k*pi)^2)*t);
end
plot(v,t)
Thanks
Alice

Réponse acceptée

Torsten
Torsten le 6 Avr 2023
Modifié(e) : Torsten le 6 Avr 2023
t = linspace(0,0.1,100);
x = linspace(0,1,100).';
n = 1000;
f = @(t) sum(6./(pi+6*(0:n)*pi).*sin(x.*(0:n)).*exp(-(pi/6+(0:n)*pi).^2*t),2);
for j = 1:numel(t)
F(:,j) = f(t(j));
end
figure(1)
plot(x,[F(:,1),F(:,10),F(:,15),F(:,20),F(:,100)])
figure(2)
plot(t,[F(1,:);F(10,:);F(15,:);F(20,:);F(100,:)])
  10 commentaires
Torsten
Torsten le 6 Avr 2023
Modifié(e) : Torsten le 6 Avr 2023
You can use
t = linspace(0,0.1,100);
x = linspace(0,1,100).';
n = 1000;
f = @(t) sum(6./(pi+6*(0:n)*pi).*sin(x.*(0:n)).*exp(-(pi/6+(0:n)*pi).^2*t),2);
for j = 1:numel(t)
F(:,j) = f(t(j));
end
or
t = linspace(0,0.1,100);
x = linspace(0,1,100).';
n = 1000;
f = @(t) sum(6./(pi+6*(0:n)*pi).*sin(x.*(0:n)).*exp(-(pi/6+(0:n)*pi).^2*t),2);
F = cell2mat(arrayfun(@(t)f(t),t,'UniformOutput',0));
or
t = linspace(0,0.1,100);
x = linspace(0,1,100).';
n = 1000;
F = zeros(numel(x),numel(t));
for i = 1:numel(x)
xv = x(i);
for j = 1:numel(t)
tv = t(j);
for k = 0:n
F(i,j) = F(i,j) + 6/(pi+6*k*pi)*sin(xv*k)*exp(-(pi/6+k*pi)^2*tv);
end
end
end
F should be the same for all three codes, but I think for beginners, the last code is the easiest to understand.
Alice K
Alice K le 6 Avr 2023
amazing, thank you so much for all you help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by