Whats the value of B ??
1 view (last 30 days)
Show older comments
mr mo
on 10 Jun 2016
Commented: Walter Roberson
on 10 Jun 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 Comments
Accepted Answer
Walter Roberson
on 10 Jun 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 Comments
Walter Roberson
on 10 Jun 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) );
More Answers (1)
Torsten
on 10 Jun 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 Comments
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!