Uploaded by Ryan Schmidt

homework template (21)

advertisement
ROSE-HULMAN INSTITUTE OF TECHNOLOGY
Department of Mechanical Engineering
ME 123
Computer Programming
Ryan Schmidt
CM 2599
ME 123 Section 02
Due Date: 11/2/2020
Day (32) Exercises
Exercise 1 _________
Exercise 2 _________
Exercise 3 _________
Exercise 4 _________
Total
_________
Honor Statement (Choose one)
1. I pledge my honor that I did not copy any of this homework, but I did receive help from
________________________________________.
(the name of the students should go here)
__________________________________________________
(your signature)
or
2. I pledge my honor that I did not copy any of this homework and this work is entirely my own.
___________Ryan Schmidt_______________________________________
(your signature)
Exercise 1
MATLAB code:
clc
clear variables
file_n=fopen('Day32_Ex1.txt','w')
x=[0:0.1:2];
y=1-x.^2;
tol=1.0e-02;
findit=5/10;
for i=1:length(x)
if (x(i) < (findit+tol)) && (x(i) > (findit-tol))
fprintf('The %1.0fth entry is 0.5. \n',i)
end
end
plot(x,y,'k',x(6),y(6),'ro')
title('Function')
xlabel('X VALUES')
ylabel('Y VALUES')
legend('Function','Closest Point')
Output to text file: ^
Exercise 2
MATLAB code:
clc
clear variables
file_n=fopen('Day32_Ex2.txt','w')
x=[0:0.001:2];
y1=1-x.^2;
y2=x;
plot(x,y1,'b',x,y2,'r',x(619),y2(619),'ko')
title('Plotted Intersection')
xlabel('X-Values')
ylabel('Y-Values')
legend('Y1','Y2','Intersection')
tol=1.0e-04;
findit=618/1000;
for i=1:length(x)
if (x(i) < (findit+tol)) && (x(i) > (findit-tol))
fprintf('The %1.0fth entry is 0.618. \n',i)
end
end
Output to text file:
Exercise 3
MATLAB code:
clc
clear variables
file_n=fopen('Day32_Ex2.txt','w')
x=[0:0.001:2];
y1=1-x.^2;
y2=x;
plot(x,y1,'b',x,y2,'r',x(619),y2(619),'ko')
title('Plotted Intersection')
xlabel('X-Values')
ylabel('Y-Values')
legend('Y1','Y2','Intersection')
tol=1.0e-04;
findit=618/1000;
i=find(abs(x-findit)<tol);
fprintf('The %1.0ft entry is 0.618. \n',i)
Output to text file:
The 619t entry is 0.618.
(with same plot from EX:2 aswell)
Exercise 4
MATLAB code:
clc
clear variables
file_n=fopen('Day32_Ex3.txt','w')
x=[0:0.001:2];
y=1+x-x.^2;
[maxy,max_index]=max(y);
fprintf( ' y has a min value of %6.4f at x=%4.2f \n',maxy,x(max_index))
plot(x,y,'b',x(max_index),y(max_index),'ro')
title('Plotted Maximum Point')
xlabel('X-Values')
ylabel('Y-Values')
legend('Y','MAX-Point')
Output to text file:
y has a min value of 1.2500 at x=0.50
Download