I have system of linear equations in three unknowns.
- x(1)-1+(1-x(3))^(M1-1)=0
- x(2)-1+(1-x(3))^(M2-1)=0
- x(3)-(1+x(1)^(R1+1)+I+J)*e*Pi=0
However, the results in my Matlab is wrong.
How can I do to optimize this code? Or what's wrong in my codes?
Following is my Matlab code:
function T=Analysis0828(R1,R2,W1,W2,M,a1,a2,e)x = sym('x',[1 2 3]);%Equations
M1=(M/(a1/a1+a2))M2=(M/(a2/a1+a2))G=((W1+1)/2)*(x(1)*(1-x(1)^(R1)))/(1-x(1));H=(x(1)^(R1+1))*((W2+1)/2)*x(2)*(1-x(2)^(R2))/(1-x(2));Pi=(1+e+(x(1)^(R1+1))*e+(G+H)*e)^(-1);I=x(1)*(1-x(1)^(R1))/(1-x(1));J=x(1)*(1-x(2)^(R2))/(1-x(2));my_eqns = [x(1)-1+(1-x(3))^(M1-1); x(2)-1+(1-x(3))^(M2-1); x(3)-(1+x(1)^(R1+1)+I+J)*e*Pi]; g = matlabFunction(my_eqns); F = my_vectorize(g);x0 = [0.4,0.5,0.01];s = fsolve(F,x0);T=(M1*M1*(1-s(1))*s(3)+M2*M2*(1-s(2))*s(3))/M
my_vectorize funtion code is as follows
function f_vec = my_vectorize(fun) f_vec = @fun_vectorize; function out = fun_vectorize(x) x = num2cell(x); out = fun(x{:}); end end
When inputs is (3, 5, 5, 2, 10, 1, 1, 1)
And my results are
s = 0.9557 0.5413 0.9557
Best Answer