Azzera filtri
Azzera filtri

Plotting a function with for loop

1 visualizzazione (ultimi 30 giorni)
Kushagra Kirtiman
Kushagra Kirtiman il 19 Ago 2022
Risposto: Star Strider il 19 Ago 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)

Risposte (1)

Star Strider
Star Strider il 19 Ago 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.
.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by