Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%
- %Headedr
- clc;
- disp('Cameron Tucker')
- disp('Eng 1181')
- %%
- %Problem 1
- fprintf('\nProblem 1\n')
- [r1,r2] = Func1;
- fprintf('\nPart a)\n')
- fprintf('The first answer is: %f \n',r1)
- fprintf('The second answer is: %f \n',r2)
- fprintf('\nPart b)\n')
- ax = gca;
- ax.XTick = 0:pi/4:2*pi;
- ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi','5\pi/4','3\pi/2','7\pi/4','2\pi'};
- fplot(@(x) sin(x*3)*cos(x),[0 2*pi]);
- %%
- %Problem 2
- fprintf('Problem 2\n\n')
- fprintf('Triangle 1\n')
- A1 = Func2;
- fprintf('The area of triangle 1 is: %0.3f\n',A1)
- fprintf('\nTriangle 2\n')
- A2 = Func2;
- fprintf('The area of triangle 2 is: %0.3f\n',A2)
- fprintf('\nTriangle 3\n')
- A3 = Func2;
- fprintf('The area of triangle 3 is: %0.3f\n',A3)
- %%
- %Problem 3
- fprintf('\nProblem 3\n')
- mpg = input('How many miles to the gallon do you get? ');
- gallons = input('How many gallons does your tank need? ');
- StationA = input('What is the price of gas at station A? ');
- StationB = input('What is the price of gas at station B? ');
- dist = input('What is the distance between the stations in miles? ');
- price = StationA;
- costa = Func3(gallons,price);
- price = StationB;
- gallons = gallons+dist/mpg;
- costb = Func3(gallons,price);
- savings = costa-costb;
- if savings > 0
- fprintf('\nMoney saved by going to station B is $%0.2f\n',savings)
- elseif savings == 0
- fprintf('\nThere is no difference in cost if you drive to station B\n')
- else
- fprintf('\nMoney lost by going to station B is $%0.2f\n',-savings)
- end
- %%
- %Problem 4
- function [ r1,r2 ] = Func1( )
- %UNTITLED2 Summary of this function goes here
- % Detailed explanation goes here
- t1 = input('Enter first theta: ');
- r1= sin(3*t1)*cos(t1);
- t2 = input('Enter second theta: ');
- r2 = sin(3*t2)*cos(t2);
- end
- function [ area ] = Func2( a,b,c )
- %UNTITLED4 Summary of this function goes here
- % Detailed explanation goes here
- a = input('Enter the length of side 1: ');
- b = input('Enter the length of side 2: ');
- c = input('Enter the length of side 3: ');
- s = (a+b+c)/2;
- area = sqrt(s*(s-a)*(s-b)*(s-c));
- end
- function [ total_cost ] = Func3( gallons,price )
- %UNTITLED Summary of this function goes here
- % Detailed explanation goes here
- total_cost = gallons*price;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement