how to write code for following equation to plot graph for M vs F with respect Q?

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)

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

i would like to say thank you for your solution, when i run this code it showing M vs Q,but actually i want to plot M vs F.
Add F as the first argument of plot.
figure; plot(F, M, 'o')

This question is closed.

Products

Asked:

on 8 Sep 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!