Whats the value of B ??
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File 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!