Solving equation with four unknowns
조회 수: 8 (최근 30일)
이전 댓글 표시
clear all
aa=1.5;
m=(0.5)^(aa);
syms x y w z
S=vpasolve([x^2+y^2+z^2+w^2==m, x+y+z+w==1],[x y z w],[0 1],'Random',true)
S =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
z: [1×1 sym]
w: [1×1 sym]
>> S.x
ans =
0.5 + 0.27059805007309849219986160268319i
>> S.y
ans =
0.5 - 0.27059805007309849219986160268319i
>> S.z
ans =
0
>> S.w
ans =
0
>>
I am trying to find four probalities (x,y, z, and w) such that:
x^2+y^2+z^2+w^2==m, and x+y+z+w==1; where m is a constant. I wrote the code as above, but because i specified the range of probabilities to [0 1], i get yhe following message: "Incompatible starting points and variables". When i remove the range, then i get unique solutions like above. But i feel there should be more that one solution to such an equation. I will appreciate any help.
Thanks
댓글 수: 0
채택된 답변
Star Strider
2019년 5월 31일
You need to explore the solutions in detail:
aa=1.5;
m=(0.5)^(aa);
syms x y w z z1 z2
S=solve([x^2+y^2+z^2+w^2==m, x+y+z+w==1],[x y z w],'ReturnConditions',true)
X = solve(S.x,[z1,z2]);
Roots = vpa(X.z1)
produces:
Roots =
0.5 + 0.27059805007309849219986160268319i
0.5 - 0.27059805007309849219986160268319i
These are ‘z1’ and ‘z2’, the two roots of your equation.
댓글 수: 2
Star Strider
2019년 5월 31일
As always, my pleasure.
The absolute values of both are the same, that being: 0.568527312187693, so they fit within your constraints in that respect. You are solving two equations in four unknowns, so only two unknowns will have nonzero values.
If you want only real results, you can declare:
syms x y w z real
or:
syms x y w z z1 z2 real
however the result are empty solutions.
Perhaps if you post a new Question specifically describing your problem and the probabilities you want to estimate, and in those terms, you can resolve this. I doubt that it’s possible to go further here.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!