Plotting a function with for loop

1 vue (au cours des 30 derniers jours)
Kushagra Kirtiman
Kushagra Kirtiman le 19 Août 2022
I want to plot Function G with k but function G depends on the values of i which is incremented by 1. Is there a way to plot this function in MATLAB. I have written the code but it is not working. Any help is appreciated
a=100.400
b=230.033
c1=1
c2=4
k=1:100
for i =1:1:100
G=1+c1*exp(-j*i*a)+c2*exp(-j*i*b)
end
plot(G,k)

Réponses (1)

Star Strider
Star Strider le 19 Août 2022
Subscript ‘G’ to save it as a vector —
a=100.400;
b=230.033;
c1=1;
c2=4;
k=1:100;
for i =1:1:100
G(i)=1+c1*exp(-j*i*a)+c2*exp(-j*i*b);
end
figure
plot(real(G),k)
hold on
plot(imag(G),k)
hold off
grid
legend('Re','Im')
xlabel('G')
ylabel('k')
figure
plot(k,real(G))
hold on
plot(k,imag(G))
hold off
grid
legend('Re','Im')
xlabel('k')
ylabel('G')
Make appropriate changes to get the result you want.
.

Catégories

En savoir plus sur 2-D and 3-D 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