Plotting a function with for loop

1 view (last 30 days)
Kushagra Kirtiman
Kushagra Kirtiman on 19 Aug 2022
Answered: Star Strider on 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)

Answers (1)

Star Strider
Star Strider on 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.
.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!