Whats the value of B ??
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
mr mo
il 10 Giu 2016
Commentato: Walter Roberson
il 10 Giu 2016
Hello every one.
I wanna find the value of B, that make the variable Z=0.8 or very close to 0.8. How can I do that in Matlab ?
here is the sample of my code .
n=10;
C=[0.2 0.55 0.7 0.8 0.99 0.1 0.24 0.33 0.44 0.74];
P=exp(-B*C);
P=P/sum(P);
z = sum (P(1 : n/2));
With best regards.
0 Commenti
Risposta accettata
Walter Roberson
il 10 Giu 2016
syms B
n = 10;
C = [0.2 0.55 0.7 0.8 0.99 0.1 0.24 0.33 0.44 0.74];
P = exp(-B.*C);
P2 = P./sum(P);
z = sum(P2(1 : n/2));
Bval = vpasolve(z == 0.8,B);
However, this will give only one of the 89 solutions. It happens to be the only real-valued solution so that might be good enough for you.
2 Commenti
Walter Roberson
il 10 Giu 2016
If you construct the other lines symbolically in B then use
subs(expression, B, Bval)
If the other lines expect B numerically, then use
syms Bs
n = 10;
C = [0.2 0.55 0.7 0.8 0.99 0.1 0.24 0.33 0.44 0.74];
P = exp(-Bs.*C);
P2 = P./sum(P);
z = sum(P2(1 : n/2));
B = double( vpasolve(z == 0.8, Bs) );
Più risposte (1)
Torsten
il 10 Giu 2016
function main
x0=1;
sol=fzero(@fun,x0)
function y=fun(x)
n=10;
C=[0.2 0.55 0.7 0.8 0.99 0.1 0.24 0.33 0.44 0.74];
for k=1:length(x)
xk=x(k);
P=exp(-xk*C);
P=P/sum(P);
y(k)=0.8-sum(P(1:n/2));
end
Best wishes
Torsten.
0 Commenti
Vedere anche
Categorie
Scopri di più su Sequence and Numeric Feature Data Workflows 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!