


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This course provides an introduction to programming and problem solving using a high-level programming language. We use matlab to practice our concepts in coding. Some important keywords in this homework are: Spherical Triangle, Area and Excess, Special Triangle, Testing Our Code, Distance, Triangular Area, Distance Converter, Setun Returns, Soccer Ball Toss
Typology: Exercises
1 / 4
This page cannot be seen from the preview
Don't miss anything!



function [Area, E] = spherical triangle(A,B,C,R) % Returns the area of a spherical triangle with % spherical angles A,B,C
E = A + B + C − pi; Area = Rˆ2 (^) * E;
LA = input('Enter the longtitude value for A in degrees: '); LB = input('Enter the longtitude value for B in degrees: ');
if LA < LB C = (LB − LA)pi/180; else C = (360 + LB − LA)pi/180; end
A = pi/2; % longtitudes are perpendicular to the equator B = pi/2;
R = input('Enter the value for the radius: ');
[Area, E] = spherical triangle(A,B,C,R);
disp('The area of the special triangle is '); disp(Area); disp('The excess value is '); disp(E);
A = input('Enter the angle A: '); B = input('Enter the angle B: '); C = input('Enter the angle C: '); R = input('Enter the radius R: ');
[Area, E] = spherical triangle(A,B,C,R);
fprintf('The area of the triangle is %f\n', Area); fprintf('The spherical excess is %f\n', E);
function dAB = distance(xA,xB,yA,yB,zA,zB) % Returns the distance between points A and B which are specified % using their cartesian coordinates in 3dimensions.
dAB = sqrt((xA−xB)ˆ2+(yA−yB)ˆ2+(zA−zB)ˆ2);
function [Area,dAB,dBC,dCA] = triangle area(xA,xB,xC,yA,yB,yC,zA,zB,zC) % Returns the area and side lengths of a triangle. The input consists % of the cartesian coordinates of vertices in 3−dimensions.
dAB = distance(xA,xB,yA,yB,zA,zB); dBC = distance(xB,xC,yB,yC,zB,zC); dCA = distance(xC,xA,yC,yA,zC,zA);
s = (dAB + dBC + dCA) / 2; % semi−perimeter
Area = sqrt(s(s−dAB)(s−dBC)*(s−dCA)); % dont forget (^) *
function x = coin toss() x = rand > 0.5;
function x = ball toss() x = rand > 0.2843;