Hello guys how can put this equation into matlab FAR is probability i would like to use for loop to find solution when various n=0:1:4 and plot this

2 Ansichten (letzte 30 Tage)
q1=0.1587;
q2=1-q1;
for n=0:1:4;
FAR=q1.^n.*(1+q2+q2.^2+q2.^3)/((q1.^n.*(1+q2+q2.^2+q2.^3)+(q2.^n.*(1+q1+q1.^2+q1.^3))))
plot(n,FAR)
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 18 Dez. 2021
q1=0.1587;
q2=1-q1;
for n=0:1:4;
FAR=q1.^n.*(1+q2+q2.^2+q2.^3)/((q1.^n.*(1+q2+q2.^2+q2.^3)+(q2.^n.*(1+q1+q1.^2+q1.^3))))
plot(n,FAR, '*-');
hold on
end
FAR = 0.7258
FAR = 0.3330
FAR = 0.0861
FAR = 0.0175
FAR = 0.0033
xlim([-.5 4.5])
hold off
You are only plotting one point at a time, and MATLAB never draws connecting lines if you only plot one point at a time. If you want connecting lines you should record your n values and your results and plot() after the loop.
q1=0.1587;
q2=1-q1;
nvals = linspace(0,4);
num_n = length(nvals);
FAR = zeros(1, num_n);
for nidx = 1 : num_n
n = nvals(nidx);
FAR(nidx) = q1.^n.*(1+q2+q2.^2+q2.^3)/((q1.^n.*(1+q2+q2.^2+q2.^3)+(q2.^n.*(1+q1+q1.^2+q1.^3))));
end
plot(nvals, FAR)
xlim([-.5 4.5])

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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