function - Solving the system of non-linear equations in MATLAB by fsolve -
i have code produces vector in matlab, example following 3 component vector (n=3
):
a1_1 - sin((17*a1_1)/60 + a2_1/8 + a3_1/40 - 0.153233) (15*a1_1)/16 + a2_1/4 + a3_1/32 - sin((17*a1_1)/60 + a2_1/8 + a3_1/40 - 0.0282326) (3*a1_1)/4 + a2_1/2 + a3_1/8 - sin((17*a1_1)/60 + a2_1/8 + a3_1/40 + 0.846767)
as can see each component non-linear equation. 3 component of vector forms system of 3 non-linear equations having it's variables named a1_1
, a1_2
and a1_3
. want solve system fsolve
.
how do arbitrary n
?
to use fsolve
, function must accept vector input , return vector of same size. in case can accomplish anonymous function:
f = @(a)[a(1) - sin(17*a(1)/60 + a(2)/8 + a(3)/40 - 0.153233);... 15*a(1)/16 + a(2)/4 + a(3)/32 - sin(17*a(1)/60 + a(2)/8 + a(3)/40 - 0.0282326);... 3*a(1)/4 + a(2)/2 + a(3)/8 - sin(17*a(1)/60 + a(2)/8 + a(3)/40 + 0.846767)]; n = 3; a0 = zeros(n,1); % initial guess opts = optimoptions('fsolve','display','iter','tolfun',1e-8); [a_sol,a_val,exitflag] = fsolve(f,a0,opts)
this returns
a_sol = -0.002818738864459 -0.687953796565011 9.488284986072076
of course there may more 1 solution, larger n
. can choose initial guess find others. see documentation fsolve
, optimoptions
further details on on specifying options.
Comments
Post a Comment