Uploaded by Anar Nasirov

Numerical_Methods

advertisement
Anar Nasirov 190223086
MKT 212 Numerical Methods in Mechatronics Engineering
Spring 2021-2022
Assignment #2
1. (20 pts) The height h(t) and velocity v(t) of a object thrown upward at any moment are given as follows. Where
v0=initial velocity, ϴ=the initial angle with the horizontal plane and g=gravity of earth. Air resistance is neglected.
Given the following parameter values; ϴ= 50 degree, v0= 10 m/s and g = 9.81 m/s2, find the time t which minimizes
the velocity using an initial interval of [0, 3]
a)
clear all; close all; clc;
t=0:0.001:3;
theta = 50; % angle between velocity vector and ground (the unit is degree)
vo = 10; % the unit is m/s
g = 9.81; % the unit is m/s^2
v = sqrt(vo^2-2*vo*g*t*sind(theta)+(g*t).^2); %velocity
%plotting
plot(t,v,'Linewidth',2);
grid on;
xlabel('time')
ylabel('velocity')
hold on;
% finding and marking minimum velocity
n = find(v == min(v));
stem(t(n),v(n),'Linewidth',2);
%printing the result
formatSpec = 'Minimum velocity is %5.5f m/s at %5.5f s in [0,3] arrival\n ';
fprintf(formatSpec,v(n),t(n));
Anar Nasirov 190223086
ℎ(𝑡𝑡 ) = 𝑣𝑣0 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 − 0.5𝑔𝑔𝑡𝑡 2
ℎ′ (𝑡𝑡 ) = 𝑣𝑣0 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 − 𝑔𝑔𝑔𝑔 = 0
b)
𝒕𝒕 =
c) i-) First iteration:
𝑑𝑑 =
𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏(𝟓𝟓𝟓𝟓)
= 𝟎𝟎. 𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕 𝒔𝒔
𝒈𝒈
𝒙𝒙𝒍𝒍 = 𝟎𝟎 𝒙𝒙𝒖𝒖 = 𝟑𝟑
√5 − 1
(𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙 ) = 1.8541
2
𝑥𝑥1 = 𝑥𝑥𝑙𝑙 + 𝑑𝑑 = 1.8541
𝑥𝑥2 = 𝑥𝑥𝑢𝑢 − 𝑑𝑑 = 1.1459
𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙 > 0.005 − 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
𝑓𝑓(𝑥𝑥1 ) = ℎ(1.8541) = −2.657
𝑓𝑓(𝑥𝑥2 ) = ℎ(1.146) = 2.337
𝑓𝑓(𝑥𝑥2 ) > 𝑓𝑓(𝑥𝑥1 ) => 𝑥𝑥𝑙𝑙 = 0
Second iteration:
𝑥𝑥2 = 𝑥𝑥𝑢𝑢 −
𝑥𝑥𝑢𝑢 = 𝑥𝑥1 = 1.8541
𝑥𝑥1 = 𝑥𝑥2 = 1.146
√5 − 1
√5 − 1
(𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙 ) = 1.8541 −
(1.85 − 0) = 0.7066
2
2
𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙 = 1.85 − 0 > 0.005 − 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
𝑓𝑓(𝑥𝑥1 ) = ℎ(1.146) = 2.337
𝑓𝑓(𝑥𝑥2 ) = ℎ(0.7066) = 2.9638
𝑓𝑓(𝑥𝑥2 ) > 𝑓𝑓(𝑥𝑥1 ) => 𝑥𝑥𝑙𝑙 = 0
ii-)
𝑥𝑥2 = 𝑥𝑥𝑢𝑢 −
𝑥𝑥𝑢𝑢 = 𝑥𝑥1 = 1.146
𝑥𝑥1 = 𝑥𝑥2 = 0.7066
√5 − 1
√5 − 1
(𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙 ) = 1.146 −
(1.146 − 0) = 0.4377
2
2
%V HAVE AN MINIMUM VALUE AT [0,3] INTERVAL AND THAT WILL BE SAME PO?NT FOR
%MAXIMUM OF THE -V FUNTION LIKE THE SHOWN IN Figure 1 AT PART 1
%I USE THE ALGORITHM TO FIND MAXIMUM VALUE SO I CHANGED MY FUNCTION (-1)*v
%PART 1
clear all; close all; clc;
t=0:0.001:3;
theta = 50; % angle between velocity vector and ground (the unit is degree)
vo = 10; % the unit is m/s
g = 9.81; % the unit is m/s^2
v = sqrt(vo^2-2*vo*g*t*sind(theta)+(g*t).^2); %velocity
Anar Nasirov 190223086
%plotting
plot(t,-v,'Linewidth',2);
grid on;
xlabel('time')
ylabel('velocity')
hold on;
% finding and marking maximum point of -v
n = find(v == min(v));
stem(t(n),-v(n),'Linewidth',2);
%PART 2
clear all; clc;
syms t;
theta = 50; % angle between velocity vector and ground (the unit is degree)
vo =
10; % the unit is m/s
g =
9.81; % the unit is m/s^2
A =@(t) -(sqrt(vo^2-2*vo*g*t*sind(theta)+(g*t).^2));% Function to be optimized
xl=0;% Lower limit of the interval
xu=3;% upper limit of the interval
epsilon=0.005;% Initial Interval
% Programming the Golden Section Search Method with displaying the Outputs
disp('***************************************************************************
*******************')
disp('Golden section search method')
range=10*epsilon;
iteration=0;
while(range>epsilon)
iteration=iteration+1;% iteration, counting the number of iterations
d=(sqrt(5)-1)/2*(xu-xl);
x1=xl+d;%calculating the point x1
x2=xu-d;%calculating the point x2
val1=A(x1);%calculating f(x1)
val2=A(x2);%calculating f(x2);
interval=[xl xu];% storing the interval as an array
range=xu-xl;%calculating the range of the interval
optimization_point= (xu+xl)/2;%Calculating the optimization point, (xl+xu)/2
fprintf('Iteration Number=%g\n',iteration)%Printing the Iteration Number
%Printing the search interval
fprintf('Search Interval=')
disp(interval)
%Printing the optimization point
fprintf('optimization point=%g\n\n\n',optimization_point)
%Adjusting the interval values for the next iteration
if(val1>val2)
xl=x2;
x2=x1;
xu=xu;
d=(sqrt(5)-1)/2*(xu-xl);
Anar Nasirov 190223086
end
end
d)
i-)
x1=xl+d;
if(val1<val2)
xl=xl;
xu=x1;
x1=x2;
d=(sqrt(5)-1)/2*(xl-xu);
x2=xu-d;
end
Anar Nasirov 190223086
2. (10 pts) An experiment is performed to define the relationship between applied stress and the time to fracture
for a type of stainless steel. Eight different values of stress are applied, and the resulting data are
Plot these data in Matlab and then develop a fitting equation to predict the fracture time for an applied stress of
23 kg/mm2 using the following methods.
b)
Anar Nasirov 190223086
3. (20 pts) Let 𝑦𝑦=sin(0.5√𝑥𝑥/𝑥𝑥) . Here, x is in radian.
a) For step = 0.1
Download