newton-raphson for 12 equations
2 views (last 30 days)
Show older comments
milad
on 24 Jul 2014
Answered: Michael Haderlein
on 24 Jul 2014
Hi friends! I need a newton-raphson code to solve 12 equations with 12 variables. I've tried to use some of the codes but I couldn't find the answer. here is my equations which matrix B is (12*12):
Alfa=.1; Beta=0; Gama=0;
syms w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12
eq1=B(1,1)*w1+B(1,2)*w2+B(1,3)*w3+B(1,4)*w4+B(1,5)*w5+B(1,6)*w6+B(1,7)*w7+B(1,8)*w8+B(1,9)*w9+B(1,10)*w10+B(1,11)*w11+B(1,12)*w12-(Alfa/((1-w1)^4)+Beta/((1-w1)^2)+Beta*Gama/(1-w1)); eq2=B(2,1)*w1+B(2,2)*w2+B(2,3)*w3+B(2,4)*w4+B(2,5)*w5+B(2,6)*w6+B(2,7)*w7+B(2,8)*w8+B(2,9)*w9+B(2,10)*w10+B(2,11)*w11+B(2,12)*w12-(Alfa/((1-w2)^4)+Beta/((1-w2)^2)+Beta*Gama/(1-w2)); eq3=B(3,1)*w1+B(3,2)*w2+B(3,3)*w3+B(3,4)*w4+B(3,5)*w5+B(3,6)*w6+B(3,7)*w7+B(3,8)*w8+B(3,9)*w9+B(3,10)*w10+B(3,11)*w11+B(3,12)*w12-(Alfa/((1-w3)^4)+Beta/((1-w3)^2)+Beta*Gama/(1-w3)); eq4=B(4,1)*w1+B(4,2)*w2+B(4,3)*w3+B(4,4)*w4+B(4,5)*w5+B(4,6)*w6+B(4,7)*w7+B(4,8)*w8+B(4,9)*w9+B(4,10)*w10+B(4,11)*w11+B(4,12)*w12-(Alfa/((1-w4)^4)+Beta/((1-w4)^2)+Beta*Gama/(1-w4)); eq5=B(5,1)*w1+B(5,2)*w2+B(5,3)*w3+B(5,4)*w4+B(5,5)*w5+B(5,6)*w6+B(5,7)*w7+B(5,8)*w8+B(5,9)*w9+B(5,10)*w10+B(5,11)*w11+B(5,12)*w12-(Alfa/((1-w5)^4)+Beta/((1-w5)^2)+Beta*Gama/(1-w5)); eq6=B(6,1)*w1+B(6,2)*w2+B(6,3)*w3+B(6,4)*w4+B(6,5)*w5+B(6,6)*w6+B(6,7)*w7+B(6,8)*w8+B(6,9)*w9+B(6,10)*w10+B(6,11)*w11+B(6,12)*w12-(Alfa/((1-w6)^4)+Beta/((1-w6)^2)+Beta*Gama/(1-w6)); eq7=B(7,1)*w1+B(7,2)*w2+B(7,3)*w3+B(7,4)*w4+B(7,5)*w5+B(7,6)*w6+B(7,7)*w7+B(7,8)*w8+B(7,9)*w9+B(7,10)*w10+B(7,11)*w11+B(7,12)*w12-(Alfa/((1-w7)^4)+Beta/((1-w7)^2)+Beta*Gama/(1-w7)); eq8=B(8,1)*w1+B(8,2)*w2+B(8,3)*w3+B(8,4)*w4+B(8,5)*w5+B(8,6)*w6+B(8,7)*w7+B(8,8)*w8+B(8,9)*w9+B(8,10)*w10+B(8,11)*w11+B(8,12)*w12-(Alfa/((1-w8)^4)+Beta/((1-w8)^2)+Beta*Gama/(1-w8)); eq9=B(9,1)*w1+B(9,2)*w2+B(9,3)*w3+B(9,4)*w4+B(9,5)*w5+B(9,6)*w6+B(9,7)*w7+B(9,8)*w8+B(9,9)*w9+B(9,10)*w10+B(9,11)*w11+B(9,12)*w12-(Alfa/((1-w9)^4)+Beta/((1-w9)^2)+Beta*Gama/(1-w9)); eq10=B(10,1)*w1+B(10,2)*w2+B(10,3)*w3+B(10,4)*w4+B(10,5)*w5+B(10,6)*w6+B(10,7)*w7+B(10,8)*w8+B(10,9)*w9+B(10,10)*w10+B(10,11)*w11+B(10,12)*w12-(Alfa/((1-w10)^4)+Beta/((1-w10)^2)+Beta*Gama/(1-w10)); eq11=B(11,1)*w1+B(11,2)*w2+B(11,3)*w3+B(11,4)*w4+B(11,5)*w5+B(11,6)*w6+B(11,7)*w7+B(11,8)*w8+B(11,9)*w9+B(11,10)*w10+B(11,11)*w11+B(11,12)*w12-(Alfa/((1-w11)^4)+Beta/((1-w11)^2)+Beta*Gama/(1-w11)); eq12=B(12,1)*w1+B(12,2)*w2+B(12,3)*w3+B(12,4)*w4+B(12,5)*w5+B(12,6)*w6+B(12,7)*w7+B(12,8)*w8+B(12,9)*w9+B(12,10)*w10+B(12,11)*w11+B(12,12)*w12-(Alfa/((1-w12)^4)+Beta/((1-w12)^2)+Beta*Gama/(1-w12));
F=[eq1;eq2;eq3;eq4;eq5;eq6;eq7;eq8;eq9;eq10;eq11;eq12];
thank you!
0 Comments
Accepted Answer
Michael Haderlein
on 24 Jul 2014
To solve this set of equations, I'd use the optimization toolbox function fsolve. Define your set of equations in a function (for simplification, I skip Beta and Gamma):
function w=test(x,B,Alpha)
w=B*x-Alpha./(1-x.^4);
and solve it by
fsolve(@(x) test(x,B,Alpha),ones(size(B,2),1))
Of course, B and Alpha must be defined beforehand. Does it work?
In case you cannot use the optimization toolbox, you'll find couple of files at the file exchange indexed with "Newton Raphson". I didn't read through them, but most likely, you'll find one which is supporting the same syntax.
Best regards,
Michael
More Answers (1)
Michael Haderlein
on 24 Jul 2014
fsolve provides Trust-Region-dogleg (default), Trust-Region-reflective, and Levenberg-Marquardt. I think there's no built-in Newton-Raphson, but I'm not too sure about that.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!