Plotting a summation with two variables
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
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
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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!