Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1) To solve a system of nonlinear equations:

2cosQ-6+7cosf1 -9cosf2 =0

2sinQ+7sinf1 -9sinf2 =0

In this system the input is Q and the output is f1 and f2

Create the following m file in the editor window and write your equations
in the following form:

function w=position(output, input)

w=[(2*(cos(pi*input/180)))-6+(7*cos(output(1)))-(9*cos(output(2)));

(2*sin(pi*input/180))+(7*sin(output(1)))-(9*sin(output(2)))];

End

Note that your m file name must be the same as the function name “position”

To solve this system for any value of Q we can create another m file with the following:

close
clc %this line just clears your command window
i=1;

options = optimset('display', 'off');

for theta=0:1:360 % make a for loop and start with our


%input (theta = 0) and continue till (theta =
360)

the(i)=theta; % saves each value of the input theta in an array

theta34(:,i)=fsolve(@position,[1 1],options,theta)*180/pi;

%call the position function with input “theta” and


%save the output” phi 1 and phi 2” in array “theta34”

%the output of the function is multiplied by 180/pi


%because the sin and cos functions in MATLAB is by
%default in radians so we just convert the output or use
%cosd and sind which is in degrees.

i=i+1;

end

plot(the(1,:),theta34(1,:));
hold;
plot(the(1,:),theta34(2,:));
grid;

Note that variable “theta34” in the workspace will have the size of 2 x 361. The first row
contains the first output “phi 1” and the column contains the value of the output as the value
of theta changes from 0 to 360 hence the 361.

You might also like