Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING MATLAB, please do #2 and #3 2. Assume we have a solar panel on a platform

ID: 3805230 • Letter: U

Question

USING MATLAB, please do #2 and #3

2. Assume we have a solar panel on a platform attached to a motor. Our motor is a step motor that controls the angle of our solar panel. This means that it moves at a set increment of 0.01 degrees every time we tell it to move. Our panel will always start at an angle of solar = 0 every day. Write a function that determines how many steps the step motor needs to increment to get within one step (0.01 degrees) of a given angle. It should take an input of an angle, and return two outputs: - An integer number of steps. For instance, an input of -50.2525 degrees would return 5025 steps. - A direction, positive or negative. This should be 1 for positive angles and -1 for negative angles. -50.2525 would return -1 for your second output.

3. Write another function that simulates your step motor. It should take an angle in degrees and a direction (-1 or 1) as two inputs, and return a new angle that is either 0.01 degrees more or less than the input angle for positive and negative directions, respectively. For example, the inputs 90 and -1 would return the output 89.99.

Explanation / Answer

function [steps,direction] = myfun(angle)
i=0;
steps=0;

diretion=1;
if angle<0
direction=-1;
end

angle=abs(angle);

while i<=angle-0.01

steps=steps+1;
i=i+0.01;
end
end

%-------------------------------------

%calling in this fashion

%[steps,direction]=myfun(-50.2525);
%steps
%direction

---------------------------------------

2.

function [newangle] = fun2(angle,direction)

if(direction==1)
newangle=angle+0.01;

else
newangle=angle-0.01;
end
end

% call in this fashion
% angle2=fun2(90,-1)
%angle2