## Whats the value of B ??

### mr mo (view profile)

on 10 Jun 2016
Latest activity Commented on by Walter Roberson

on 10 Jun 2016

### Walter Roberson (view profile)

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.

### Walter Roberson (view profile)

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.

mr mo

### mr mo (view profile)

on 10 Jun 2016
But I want to use the variable B in the Next other lines of my code, and here the variable B becomes symbolic, How can I use B in other lines ?? with best regards
Walter Roberson

### Walter Roberson (view profile)

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) );

### Torsten (view profile)

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.