Filter löschen
Filter löschen

Plotting a function with for loop

1 Ansicht (letzte 30 Tage)
Kushagra Kirtiman
Kushagra Kirtiman am 19 Aug. 2022
Beantwortet: Star Strider am 19 Aug. 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)

Antworten (1)

Star Strider
Star Strider am 19 Aug. 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.
.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by