how to write code for following equation to plot graph for M vs F with respect Q?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
M=(sqrt((1+(1-(F.^-2))).^2+(((3.14).^2/8)*Q*(F-(F.^-1))).^2)).^-1;
this is the equation, which i want to plot.
F (range: 1 to 2 with step size of 0.2) and for different values of Q (range : 1 to 5 with step size of 1).
thank you
Answers (1)
mizuki
on 8 Sep 2016
The easiest way is to use double for-loop
q = 1;
M = zeros(5,6);
for Q = 1:1:5
f= 1;
for F = 1:0.2:2
M(q,f) =(sqrt((1+(1-(F.^-2))).^2+(((3.14).^2/8)*Q*(F-(F.^-1))).^2)).^-1;
f = f+1;
end
q = q+1;
end
figure;plot(M, 'o')
If you care about the speed, vectorize it.
f = 1;q = 1;
F = 1:0.2:2;
Q = 1:1:5;
M = zeros(length(F),length(Q));
[F_mesh Q_mesh] = meshgrid(F, Q);
M =( sqrt( ( 1 + (1-(F_mesh.^-2))).^2 + (((3.14).^2/8) *Q_mesh .* (F_mesh-(F_mesh.^-1))).^2) ).^-1;
figure;plot(M, 'o')
2 Comments
vijay bhaskar reddy
on 8 Sep 2016
mizuki
on 12 Sep 2016
Add F as the first argument of plot.
figure; plot(F, M, 'o')
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!