Whats the value of B ??

조회 수: 1 (최근 30일)
mr mo
mr mo 2016년 6월 10일
댓글: Walter Roberson 2016년 6월 10일
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
Walter Roberson 2016년 6월 10일
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
mr mo
mr mo 2016년 6월 10일
Thanks for your help
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 2016년 6월 10일
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) );

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2016년 6월 10일
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.

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by