Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. %%
  2. %Headedr
  3. clc;
  4. disp('Cameron Tucker')
  5. disp('Eng 1181')
  6. %%
  7. %Problem 1
  8. fprintf('\nProblem 1\n')
  9. [r1,r2] = Func1;
  10. fprintf('\nPart a)\n')
  11. fprintf('The first answer is: %f \n',r1)
  12. fprintf('The second answer is: %f \n',r2)
  13. fprintf('\nPart b)\n')
  14. ax = gca;
  15. ax.XTick = 0:pi/4:2*pi;
  16. ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi','5\pi/4','3\pi/2','7\pi/4','2\pi'};
  17. fplot(@(x) sin(x*3)*cos(x),[0 2*pi]);
  18. %%
  19. %Problem 2
  20. fprintf('Problem 2\n\n')
  21. fprintf('Triangle 1\n')
  22. A1 = Func2;
  23. fprintf('The area of triangle 1 is: %0.3f\n',A1)
  24. fprintf('\nTriangle 2\n')
  25. A2 = Func2;
  26. fprintf('The area of triangle 2 is: %0.3f\n',A2)
  27.  
  28. fprintf('\nTriangle 3\n')
  29. A3 = Func2;
  30. fprintf('The area of triangle 3 is: %0.3f\n',A3)
  31. %%
  32. %Problem 3
  33. fprintf('\nProblem 3\n')
  34. mpg = input('How many miles to the gallon do you get? ');
  35. gallons = input('How many gallons does your tank need? ');
  36. StationA = input('What is the price of gas at station A? ');
  37. StationB = input('What is the price of gas at station B? ');
  38. dist = input('What is the distance between the stations in miles? ');
  39. price = StationA;
  40. costa = Func3(gallons,price);
  41. price = StationB;
  42. gallons = gallons+dist/mpg;
  43. costb = Func3(gallons,price);
  44. savings = costa-costb;
  45. if savings > 0
  46. fprintf('\nMoney saved by going to station B is $%0.2f\n',savings)
  47. elseif savings == 0
  48. fprintf('\nThere is no difference in cost if you drive to station B\n')
  49. else
  50. fprintf('\nMoney lost by going to station B is $%0.2f\n',-savings)
  51. end
  52. %%
  53. %Problem 4
  54.  
  55.  
  56.  
  57. function [ r1,r2 ] = Func1( )
  58. %UNTITLED2 Summary of this function goes here
  59. % Detailed explanation goes here
  60. t1 = input('Enter first theta: ');
  61. r1= sin(3*t1)*cos(t1);
  62. t2 = input('Enter second theta: ');
  63. r2 = sin(3*t2)*cos(t2);
  64. end
  65.  
  66.  
  67.  
  68. function [ area ] = Func2( a,b,c )
  69. %UNTITLED4 Summary of this function goes here
  70. % Detailed explanation goes here
  71. a = input('Enter the length of side 1: ');
  72. b = input('Enter the length of side 2: ');
  73. c = input('Enter the length of side 3: ');
  74. s = (a+b+c)/2;
  75. area = sqrt(s*(s-a)*(s-b)*(s-c));
  76. end
  77.  
  78.  
  79.  
  80.  
  81. function [ total_cost ] = Func3( gallons,price )
  82. %UNTITLED Summary of this function goes here
  83. % Detailed explanation goes here
  84. total_cost = gallons*price;
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement