# Plot Graph with different b Values

6 visualizzazioni (ultimi 30 giorni)
Jun Young Choi il 14 Dic 2020
Modificato: KALYAN ACHARJYA il 14 Dic 2020
b = [1/4, 1/2, 1, 2];
figure;
for i=1:b
M = 1/((1-r.^2).^2+b^2*r.^2);
plot(r,M);hold on;
end
I want to plot a graph so that M(r) graph will be shown for different values of b. Also, I want to include a legend to keep track of the four lines.
Please help!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

KALYAN ACHARJYA il 14 Dic 2020
Modificato: KALYAN ACHARJYA il 14 Dic 2020
b = [1/4, 1/2, 1, 2];
r=1:0.01:5; % Example Define r, array data
for i=1:length(b)
M=1./((1-r.^2).^2+b(i)^2*r.^2);
plot(r,M);
hold on;
end
legend('b=1/4','b=1/2','b=1','b=2');
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Timo Dietz il 14 Dic 2020
Modificato: Timo Dietz il 14 Dic 2020
There is no declaration of 'r'. I guess it should be instead of 'i'?
Not sure what exactly you want to plot and/or how 'M' should look like.
In case you want to plot each trace versus b, you can do this:
b = [1/4, 1/2, 1, 2];
figure;
for r=b
M = 1./((1-r^2)^2+b.^2*r^2);
plot(b,M);hold on;
end
legend({'r=0.25', 'r=0.5', 'r=1', 'r=2'});
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### 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