MATLAB Now let’s put it all together in a modular program to simulate our solar
ID: 3807561 • Letter: M
Question
MATLAB Now let’s put it all together in a modular program to simulate our solar panel being set to the ideal angle for a certain day, the incident angle of the sun’s rays at solar noon! Write a program that calls all three of the previous functions you have called. It should take in two inputs: a day of the year and a latitude. It should call your first function to get the incident angle of the sun’s rays. It should call your second function to determine the number of steps your motor needs to take, and the direction those steps need to go in. It should call your third function inside of a loop to simulate the motor being stepped to the desired angle. Add a 0.1 second pause after each motor adjustment, and display the current angle of the motor in the command line. This is to simulate the motor slowly adjusting to the correct angle. You will want to use the built in MATLAB functions “pause” and “disp” to do this. You can also use the “clc” command so that you only ever see one number in the command line at a time. Your function should return one output, the final angle of the motor. For example, if your inputs were latitude 40 and the 60th day of the year, your final angle should be -47.39 degrees.
3 Previous Functions
1st) function incangle = inclination_angle(day,latitude)
decangle = 23.45*sin(2*pi*((284+day)/362.5));%implementing declination angle
incangle = acosd((cosd(decangle)*cosd(latitude))+(sind(decangle)*sind(latitude)));%implementing inclination angle
end
2nd)function [No_of_step,direction]=solar(angle_of_turn)
y1=angle_of_turn/0.01
No_of_step=round(y1);
if angle_of_turn<0
direction=-1
else
direction=1
end
end
3rd)
function [ newAngle ] = newAngle( angle, direction )
if direction<0
newAngle=angle-0.01;
else
newAngle=angle+0.01;
end
end
Explanation / Answer
function incangle = inclination_angle(day,latitude)
decangle = 23.45*sin(2*pi*((284+day)/362.5));%implementing declination angle
incangle = acosd((cosd(decangle)*cosd(latitude))+(sind(decangle)*sind(latitude)));%implementing inclination angle
end
function [No_of_step,direction]=solar(angle_of_turn)
y1=angle_of_turn/0.01
No_of_step=round(y1);
if angle_of_turn<0
direction=-1
else
direction=1
end
end
function [ newAngle ] = newAngle( angle, direction )
if direction<0
newAngle=angle-0.01;
else
newAngle=angle+0.01;
end
end
function angle = adjustMotor(day, latitude)
incident_angle = inclination_angle(day, latitude)
[steps, direction] = solar(incident_angle)
angle = incident_angle
pause(0.1)
disp(angle)
for i = 1:steps
angle = newAngle(angle, direction)
pause(0.1)
disp(angle)
clc;
end
end
day = input("Enter a day in year: ")
latitude = input("Enter lattitude: ")
angle = adjustMotor(day, latitude)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.