SlideShare a Scribd company logo
1 of 21
For any help regarding Programming Homework Help
Visit :- https://www.programminghomeworkhelp.com/ ,
Email :- support@programminghomeworkhelp.com or
call us at :- +1 678 648 4277
programminghomeworkhelp.com
Question (1):
(a) Write a Matlab M-file which generates a table of error function (erf) and its derivatives
for real arguments (z) between -3 and 3 in steps of 0.25. The error function is defined by
the equation below (but is rarely evaluated by performing the integration).
The values in the table should be given with 5 decimal places. The table should have
headers explaining what the columns are. Explain how you designed the M-file and give
an example of the output.
(b) How would you change this M-file if 10 significant digits were required? Matlab M-file
should also be supplied
Question (2):
Write an M-file that reads your name in the form <first name> <middle name> <last
name> and outputs the last name first and adds a comma after the name, the first name,
and initial of your middle name with a period after the middle initial. If the names start
with lower case letters, then these should be capitalized. The M-file should not be
specific to the lengths of your name (ie., the M-file should work with anyone’s name.
Problems
programminghomeworkhelp.com
As an example. An input of thomas abram herring would generate: Herring, Thomas A.
Question (3):
Write a Matlab M-file that will compute the motion of a bicyclist and the energy used
cycling along an oscillating, sloped straight-line path. The path followed will be expressed
as
where H(x) is the height of the path above the starting height, S is a slope in m/m, A and
B are amplitudes of sinusoidal oscillations in the path. The wavelength of the oscillations is
λ. The forces acting on the bicycle are:
where Ar is the cross-sectional area of the rider, Cd is the drag coefficient, r is the density
of air and V is the velocity of the bike. For the rolling drag, Mr is the mass of the rider and
bike, g is gravitation acceleration and Cr is rolling drag coefficient.
The bicyclist puts power into the bike by pedaling. The force generated by this power is
given by
where Fr is the force produced by the rider, Pr is power used by the rider and V is
velocity that the bike is traveling (the force is assumed to act along the velocity vector of the
bike).
programminghomeworkhelp.com
Your M-file can assume that the power can be used at different rates along the path. The
energy used will be the integrated power supplied by the rider. Assume that there is
maximum value to the rider force.
Your code should allow for input of the constants above (path and force coefficients). The M-
file can assume a constant power scenario and constant force at low velocities.
As a test of your M-file use the following constants to compute:
(a) Time to travel and energy used to travel 10 km along a path specified by S=0.001, A=5.0
m, B=0.0 m and λ= 2km, with constant power use of Pr =100Watts and a maximum
force available of 20N.
(b) The position and velocity of the bike tabulated at a 100-second interval.
(c) Add graphics to your M-file which plots the velocity of the bike as a function of time and
position along the path.
Assume the following values
Cd = 0.9
Cr = 0.007
A r = 0.67 m 2
r = 1.226 km/m3
g = 9.8 m/s2
Mr = 80 kg programminghomeworkhelp.com
In this case, the Matlab M-file will not be of the type used for fortran and C/C++. Look at
the documentation on ODExx where xx is a pair of number for Ordinary Differential Equation
solutions. Your answer to this question should include:
(a) The algorithms used and the design of your M-file
(b) The Matlab M-file with your code and solution (I run your M-file).
(c) The results from the test case above.
programminghomeworkhelp.com
Solutions
Question 1:
The solution to this problem is easy in Matlab because the Erf function is built in. In the
solution we use Matlab’s vector operations to form the entries for the table in one single line.
By using the correct transpose on the results we are able to print the table with one print
statement. We also added to the solution plots of the function and its derivative.
% HW5_1: Matlab script output Erf and its derivative
%
arg = -3:0.25:3;
% Make a table with the results in it
Results = [ arg ; erf(arg) ; 2/sqrt(pi)*exp(-arg.^2) ];
fprintf('n12.010 HW05 Q01: Table of Erf and its derivativen');
fprintf('-------------------------------------n');
fprintf('| Arg x | Erf(x) | d(Erf)/dx |n');
fprintf('-------------------------------------n');
fprintf('| %7.3f | %10.5f | %10.5f |n',Results);
fprintf('-------------------------------------n');
%% Create Figure of results
% Regenerate results at finer spacing.
figure ;
arg = -3:0.05:3;
programminghomeworkhelp.com
Results = [ arg ; erf(arg) ; 2/sqrt(pi)*exp(-arg.^2) ];
plot(Results(1,:),Results(2,:),'k',Results(1,:),Results(3,:),'b');
xlabel('Argument'); ylabel('Erf dErf/dx');
legend('Erf','dErf/dx','Location','NorthWest') axis tight;
Below is shown in the output from the program for 5 significant digits. To increase the
number of significant digits, the format for the table simply needs to be changed. All of the
calculations were done with double precision and therefore no change to the variables
needs to be made.
programminghomeworkhelp.com
Figure 1. Plot of the Erf function and its derivative.
programminghomeworkhelp.com
Question (2):
This solution is also easy in Matlab using the tolower and toupper functions. The code
also detects whether two or three names have been given and changes the output
accordingly.
% HW5_2: Matlab script file to rearrange names.
%
% Ask user for name
fprintf('n----------------------------------------n');
name = input('12.010 HW 05 Q2:nEnter Name (first middle last) ','s');
%
% Convert to lower case so that we know state name = lower(name);
%
% Find the blanks in the sting
blanks = strfind(name,' ');
if length(blanks) == 1
% Only two names passed, so skip middle initial
first = name(1:blanks(1)-1);
first(1) = upper(first(1));
last = name(blanks(1)+1:length(name));
last(1) = upper(last(1));
fprintf('%s, %s n',last, first)
programminghomeworkhelp.com
elseif length(blanks) == 2
% Split of the names. The function strtok could also be used to split
% the string into parts.
first = name(1:blanks(1)-1);
middle = name(blanks(1)+1:blanks(2)-1);
last = name(blanks(2)+1:length(name));
first(1) = upper(first(1));
middlei = upper(middle(1));
last(1) = upper(last(1));
fprintf('%s, %s %s.n',last, first, middlei)
else
fprintf('Too many names or spaces in %snProgram endn',name)
End
----------------------------------------
12.010 HW 05 Q2:
Enter Name (first middle last) thomas abram herring
Herring, Thomas A.
programminghomeworkhelp.com
Question 3:
The solution to this problem is also quite easy in Matlab. We use the OED 45 1st order
differential equation solver. To use this function we also have a function that computes the
acceleration at the bike and another function that is the event detector that determines
when the bike reaches 10 km distance. For ease of coding, the variables that control the
characteristics of the bike are saved as globals. We also use an input dialog box to both set
the defaults and allow the user to change the values at runtime. Also included in the
solution is an animation and plot of the motion of the bike. To have the animation runs
smoothly we change the output interval of the differential equation solver so that we
generate more points then those that given in the standard 100 seconds separated values.
There are some interesting bugs in Matlab for plotting the velocity vectors. The quiver
option is used for this plot but in the current release of Matlab the arrowheads are
extremely large and are turned off in the plots. Also the automatic scaling of the vectors
does not generate reasonable length vectors, and so in these plots we manually set the
scale factor.
To compute the energy used during a bike ride, we simply added the derivative of the
energy to the differential equations. This way the total energy was integrated automatically
in the solution and could be output to the table as shown below.
programminghomeworkhelp.com
The solution M-files are:
% 12.010 HW 05 Q 3: Bike simulator
%
% This script m-file simulates the motions of a paper plane being
% influenced by gravity, lift and drag
%
% There are many ways to solve this problem and we will use the Matlab ODE
% solvers with event detection (the event in this case is the z-value
% hitting zero).
%
global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength terr % Define
these globals so that they will be accessible in the acceleration routine
global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength terr % Define
these globals so that they will be accessible in the acceleration routine
Grav = -9.8 ; % m/sec^2
Rho = 1.226; % kg/m^3
%----- Get the inout that we need -----
prompt = {'Track Grade (m/m)', 'Track Asin (m)', 'Track Bcos (m)', 'Wavelegth
(km)','Track Length (km)','Mass (kg)', ...
'Rider Area (m^2)', 'Drag Coefficient','Rolling coefficient','Power
programminghomeworkhelp.com
(watts)','Max Force (N)', ...
'Output Interval (sec)','Error (mm)'};
title = 'Track and Bike Parameters';
nlines = 1;
defaults =
{'0.001','5.0','0.0','2.0','10.0','80.0','0.67','0.9','0.007','100.0','20','100','1'};
% Get user inputs and save in the appropriate valuyes result =
inputdlg(prompt,title,nlines, defaults,'on');
%
Slope = eval(result{1});
As = eval(result{2});
Bs = eval(result{3});
Lambda = eval(result{4})*1000.0 ; % Convert to meters
TLength = eval(result{5})*1000.0 ; % Convert to meters
Mass = eval(result{6}) ;
Area = eval(result{7}) ;
Cd = eval(result{8}) ;
Cr = eval(result{9}) ;
Pr = eval(result{10}) ;
Fr_Max = eval(result{11}) ;
tstep = eval(result{12}) ;
terr = eval(result{13})/1000 ; % convert height error to m
programminghomeworkhelp.com
%
% Set the ODE options. hit is the name of an m-file which will detect when % we hit the
ground.
options = odeset('AbsTol',[terr terr terr terr 100],'Events','bikehit');
% Set up the initial conditions
y0 = [0.0; Bs ; 0.0 ; 0.0; 0.0];
% Set the maximum integration time to 5000 seconds. In a more general
% problem we should check to see of this is enough time
tmax = 5000;
% Solve the ODE
fprintf('n Starting new run n');
[t,y,te,ye,ie] = ode45(@bikeacc,[0:tstep:tmax],y0,options);
%
% Output the final results fprintf('---------------------------------------------------------------------n');
fprintf('12.010 HW 05 Q 3: Bike simulationn');
% Output table of values
fprintf('--------------------------------------------------------------------------n')
fprintf(' Time X pos Z pos X Vel Z Vel Energy n')
fprintf(' (sec) (m) (m) (m/s) (m/s) (Joules)n')
fprintf(' %9.3f %12.4f %10.4f %10.4f %10.4f %12.2fn',[t,y(:,1:5)]');
programminghomeworkhelp.com
fprintf('-------------------------------------------------------------------------------------------------n')
fprintf(‘ Time : %8.3f, Velocity %6.4f %6.4f n',te,ye(3),ye(4))
fprintf('Energy used: %12.2f Joules, %8.2f kcalsn', ye(5), ye(5)*0.2388e-3);
% Now animate (make as function)
%banimate(t,y);
% Re-run the solution for the animation
[ta,ya,tae,yae,iae] = ode45(@bikeacc,[0:10.0:te],y0,options);
fprintf('nTo show animation: banimate(ta,ya)n');
%
function dy = bikeacc(t, y)
% acc: Computes accelerations including drag (Cd), rolling (Cr) and
% and gravity
% y contains, [x z xdot zdot energy] and dy is the time derivative
%
global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength % Define these globals
so that they will be accessible in the acceleration routine
dy = zeros(5,1); % a column vector
%
% get the road slope for our current x position.
programminghomeworkhelp.com
theta = atan(Slope + As*cos(2*pi*y(1)/Lambda)*2*pi/Lambda -
Bs*sin(2*pi*y(1)/Lambda)*2*pi/Lambda);
%
% Compute forces: Assuming bike remains on road surface
% Drag:
vmag = sqrt(y(3)^2+y(4)^2); thetad = atan2(y(4),y(3));
dxd = -Rho*Cd*vmag^2*Area*cos(thetad)/(2*Mass);
dzd = -Rho*Cd*vmag^2*Area*sin(thetad)/(2*Mass);
dxr = +Grav*Cr*cos(theta) ;
dzr = +Grav*Cr*sin(theta) ;
%
% Get rider force
Fr_mag = Fr_Max ;
if ( vmag > 0 ) Fr_mag = Pr/vmag ;
end
if ( Fr_mag > Fr_Max ) Fr_mag = Fr_Max ; end
height = Slope*y(1) + As*sin(2*pi*y(1)/Lambda) + Bs*cos(2*pi*y(1)/Lambda);
%if ( y(2) > height + 0.1 ) Fr_mag = 0; end
dxp = Fr_mag*cos(theta)/Mass ;
dzp = Fr_mag*sin(theta)/Mass ;
% % Normal force from surface
(Grav is a negative value)
dxn = Grav*cos(theta)*sin(theta); programminghomeworkhelp.com
dzn = -Grav*cos(theta)^2;
% Get the curvature
dy2dx2 = -As*sin(2*pi*y(1)/Lambda)*(2*pi/Lambda)^2 -
Bs*cos(2*pi*y(1)/Lambda)*(2*pi/Lambda)^2;
IRc = (dy2dx2)/(1+theta^2)^(3/2);
dxc = vmag^2*sin(theta)*IRc;
dzc = vmag^2*cos(theta)*IRc;
%fprintf(' %5.2f %9.5f %9.5f %5.2f %6.4f %10.1f n',vmag, dxc, dzc, dxd, dzd, Rc)
%
% Update the dy velocity acceleration vector
dy(1) = y(3);
dy(2) = y(4);
dy(3) = dxd + dxr + dxp + dxn + dxc ;
dy(4) = dzd + dzr + dzp + dzn + dzc + Grav ;
dy(5) = Fr_mag * vmag;
function [value,isterminal,direction] = bikehit(t,y)
% Locate the time when height passes through zero in a decreasing direction
% and stop integration.
global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength
value = y(1)-TLength; % detect when end is 0.
isterminal = 1; % stop the integration
direction = 1; % negative direction
programminghomeworkhelp.com
function banimate(t,y)
% Function to animate the motion
qs = 50;
num = length(t);
hf1 = figure(1); set(hf1, 'Position',[10 100 750 400]); hold off;
pc = plot(y(1,1),y(1,2),'o','MarkerFaceColor','r','EraseMode','xor'); hold on
pq = quiver(y(1,1),y(1,2),y(1,3),y(1,4),0);
xm = y(num,1)*1.01; ym = max(y(:,2))*1.01;
xs = min(y(:,1))*1.01; ys = min(y(:,2))*1.01;
xlim([xs xm]); ylim([ys ym]);
xlabel('Distance (m)'); ylabel('Height (m)');
pt = text(xm/100,ym*0.96,'Time 0.00 s');
%daspect([1 1 1]);
drawnow;
% Release 2011a of Matlab has some strange scaling in quiver and so we
% manually set properities that should be automatically set. Also arrow
% heads are very wide so we turn them off here.
for i = 1: num
% Replace the data point
set(pc,'XData',y(i,1),'YData',y(i,2));
delete(pq); pq = quiver(y(i,1),y(i,2),y(i,3),y(i,4),qs);
set(pq,'ShowArrowHead','off','AutoScaleFactor',qs,'AutoScale','on');
otext = sprintf('Time %6.1f s',t(i));
programminghomeworkhelp.com
set(pt,'String',otext);
drawnow;
end
plot(y(:,1),y(:,2),'g');
%%
hf2 = figure(2); set(hf2, 'Position',[760 100 350 200]);
hold off; pc = plot(y(:,1),y(:,2),'o','MarkerFaceColor','r','EraseMode','normal'); hold on pq =
quiver(y(:,1),y(:,2),y(:,3),y(:,4)); set(pq,'ShowArrowHead','off'); xlabel('Distance (m)');
ylabel('Height (m)'); axis tight; ylim([-10 15]);
%%
hf3 = figure(3); set(hf3, 'Position',[760 380 350 200]);
plot(t,(sqrt(y(:,3).^2+y(:,4).^2)));
xlabel('Time (sec)'); ylabel('Total Velocity (m/s)');
The table and figures below show the results for the default solution.
programminghomeworkhelp.com
programminghomeworkhelp.com
Figure 2: Trajectory of the bike along with vectors showing its velocity (green
lines). Due to poor scaling in Matlab, no arrowheads are shown.
Figure 3: Velocity as a function of time for the bike.
programminghomeworkhelp.com

More Related Content

What's hot

Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound techniqueishmecse13
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 
FDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABFDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABAya Zaki
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical MethodsESUG
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Optimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data PerspectiveOptimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data Perspectiveপল্লব রায়
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Nagesh NARASIMHA PRASAD
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explainedPIYUSH Dubey
 
Minimal spanning tree class 15
Minimal spanning tree class 15Minimal spanning tree class 15
Minimal spanning tree class 15Kumar
 
The Digital Image Processing Q@A
The Digital Image Processing Q@AThe Digital Image Processing Q@A
The Digital Image Processing Q@AChung Hua Universit
 

What's hot (20)

Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Environmental Engineering Assignment Help
Environmental Engineering Assignment HelpEnvironmental Engineering Assignment Help
Environmental Engineering Assignment Help
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Business Logistics Assignment Help
Business Logistics Assignment HelpBusiness Logistics Assignment Help
Business Logistics Assignment Help
 
Branch and bound technique
Branch and bound techniqueBranch and bound technique
Branch and bound technique
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
FDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABFDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLAB
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Data Analysis Assignment Help
Data Analysis Assignment HelpData Analysis Assignment Help
Data Analysis Assignment Help
 
Optimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data PerspectiveOptimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data Perspective
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.Analysis of CANADAIR CL-215 retractable landing gear.
Analysis of CANADAIR CL-215 retractable landing gear.
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
 
Digtial Image Processing Q@A
Digtial Image Processing Q@ADigtial Image Processing Q@A
Digtial Image Processing Q@A
 
Minimal spanning tree class 15
Minimal spanning tree class 15Minimal spanning tree class 15
Minimal spanning tree class 15
 
The Digital Image Processing Q@A
The Digital Image Processing Q@AThe Digital Image Processing Q@A
The Digital Image Processing Q@A
 

Similar to Computation Assignment Help

Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment HelpProgramming Homework Help
 
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxmydrynan
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration MethodEconomic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration MethodIOSR Journals
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Randa Elanwar
 
Travelling Salesman Problem, Robotics & Inverse Kinematics
Travelling Salesman Problem, Robotics & Inverse KinematicsTravelling Salesman Problem, Robotics & Inverse Kinematics
Travelling Salesman Problem, Robotics & Inverse Kinematicsmcoond
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...Naoki Shibata
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 

Similar to Computation Assignment Help (20)

Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
 
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docxCSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration MethodEconomic Dispatch of Generated Power Using Modified Lambda-Iteration Method
Economic Dispatch of Generated Power Using Modified Lambda-Iteration Method
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Laboratory 7
Laboratory 7Laboratory 7
Laboratory 7
 
Fulltext
FulltextFulltext
Fulltext
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Suspension_report
Suspension_reportSuspension_report
Suspension_report
 
Matlab1
Matlab1Matlab1
Matlab1
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
MATLAB
MATLABMATLAB
MATLAB
 
Travelling Salesman Problem, Robotics & Inverse Kinematics
Travelling Salesman Problem, Robotics & Inverse KinematicsTravelling Salesman Problem, Robotics & Inverse Kinematics
Travelling Salesman Problem, Robotics & Inverse Kinematics
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
(Slides) Efficient Evaluation Methods of Elementary Functions Suitable for SI...
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 

More from Programming Homework Help

Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpProgramming Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxProgramming Homework Help
 

More from Programming Homework Help (20)

C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Python Question - Python Assignment Help
Python Question - Python Assignment HelpPython Question - Python Assignment Help
Python Question - Python Assignment Help
 
Best Algorithms Assignment Help
Best Algorithms Assignment Help Best Algorithms Assignment Help
Best Algorithms Assignment Help
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Algorithms Design Assignment Help
Algorithms Design Assignment HelpAlgorithms Design Assignment Help
Algorithms Design Assignment Help
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 
Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 

Recently uploaded (20)

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 

Computation Assignment Help

  • 1. For any help regarding Programming Homework Help Visit :- https://www.programminghomeworkhelp.com/ , Email :- support@programminghomeworkhelp.com or call us at :- +1 678 648 4277 programminghomeworkhelp.com
  • 2. Question (1): (a) Write a Matlab M-file which generates a table of error function (erf) and its derivatives for real arguments (z) between -3 and 3 in steps of 0.25. The error function is defined by the equation below (but is rarely evaluated by performing the integration). The values in the table should be given with 5 decimal places. The table should have headers explaining what the columns are. Explain how you designed the M-file and give an example of the output. (b) How would you change this M-file if 10 significant digits were required? Matlab M-file should also be supplied Question (2): Write an M-file that reads your name in the form <first name> <middle name> <last name> and outputs the last name first and adds a comma after the name, the first name, and initial of your middle name with a period after the middle initial. If the names start with lower case letters, then these should be capitalized. The M-file should not be specific to the lengths of your name (ie., the M-file should work with anyone’s name. Problems programminghomeworkhelp.com
  • 3. As an example. An input of thomas abram herring would generate: Herring, Thomas A. Question (3): Write a Matlab M-file that will compute the motion of a bicyclist and the energy used cycling along an oscillating, sloped straight-line path. The path followed will be expressed as where H(x) is the height of the path above the starting height, S is a slope in m/m, A and B are amplitudes of sinusoidal oscillations in the path. The wavelength of the oscillations is λ. The forces acting on the bicycle are: where Ar is the cross-sectional area of the rider, Cd is the drag coefficient, r is the density of air and V is the velocity of the bike. For the rolling drag, Mr is the mass of the rider and bike, g is gravitation acceleration and Cr is rolling drag coefficient. The bicyclist puts power into the bike by pedaling. The force generated by this power is given by where Fr is the force produced by the rider, Pr is power used by the rider and V is velocity that the bike is traveling (the force is assumed to act along the velocity vector of the bike). programminghomeworkhelp.com
  • 4. Your M-file can assume that the power can be used at different rates along the path. The energy used will be the integrated power supplied by the rider. Assume that there is maximum value to the rider force. Your code should allow for input of the constants above (path and force coefficients). The M- file can assume a constant power scenario and constant force at low velocities. As a test of your M-file use the following constants to compute: (a) Time to travel and energy used to travel 10 km along a path specified by S=0.001, A=5.0 m, B=0.0 m and λ= 2km, with constant power use of Pr =100Watts and a maximum force available of 20N. (b) The position and velocity of the bike tabulated at a 100-second interval. (c) Add graphics to your M-file which plots the velocity of the bike as a function of time and position along the path. Assume the following values Cd = 0.9 Cr = 0.007 A r = 0.67 m 2 r = 1.226 km/m3 g = 9.8 m/s2 Mr = 80 kg programminghomeworkhelp.com
  • 5. In this case, the Matlab M-file will not be of the type used for fortran and C/C++. Look at the documentation on ODExx where xx is a pair of number for Ordinary Differential Equation solutions. Your answer to this question should include: (a) The algorithms used and the design of your M-file (b) The Matlab M-file with your code and solution (I run your M-file). (c) The results from the test case above. programminghomeworkhelp.com
  • 6. Solutions Question 1: The solution to this problem is easy in Matlab because the Erf function is built in. In the solution we use Matlab’s vector operations to form the entries for the table in one single line. By using the correct transpose on the results we are able to print the table with one print statement. We also added to the solution plots of the function and its derivative. % HW5_1: Matlab script output Erf and its derivative % arg = -3:0.25:3; % Make a table with the results in it Results = [ arg ; erf(arg) ; 2/sqrt(pi)*exp(-arg.^2) ]; fprintf('n12.010 HW05 Q01: Table of Erf and its derivativen'); fprintf('-------------------------------------n'); fprintf('| Arg x | Erf(x) | d(Erf)/dx |n'); fprintf('-------------------------------------n'); fprintf('| %7.3f | %10.5f | %10.5f |n',Results); fprintf('-------------------------------------n'); %% Create Figure of results % Regenerate results at finer spacing. figure ; arg = -3:0.05:3; programminghomeworkhelp.com
  • 7. Results = [ arg ; erf(arg) ; 2/sqrt(pi)*exp(-arg.^2) ]; plot(Results(1,:),Results(2,:),'k',Results(1,:),Results(3,:),'b'); xlabel('Argument'); ylabel('Erf dErf/dx'); legend('Erf','dErf/dx','Location','NorthWest') axis tight; Below is shown in the output from the program for 5 significant digits. To increase the number of significant digits, the format for the table simply needs to be changed. All of the calculations were done with double precision and therefore no change to the variables needs to be made. programminghomeworkhelp.com
  • 8. Figure 1. Plot of the Erf function and its derivative. programminghomeworkhelp.com
  • 9. Question (2): This solution is also easy in Matlab using the tolower and toupper functions. The code also detects whether two or three names have been given and changes the output accordingly. % HW5_2: Matlab script file to rearrange names. % % Ask user for name fprintf('n----------------------------------------n'); name = input('12.010 HW 05 Q2:nEnter Name (first middle last) ','s'); % % Convert to lower case so that we know state name = lower(name); % % Find the blanks in the sting blanks = strfind(name,' '); if length(blanks) == 1 % Only two names passed, so skip middle initial first = name(1:blanks(1)-1); first(1) = upper(first(1)); last = name(blanks(1)+1:length(name)); last(1) = upper(last(1)); fprintf('%s, %s n',last, first) programminghomeworkhelp.com
  • 10. elseif length(blanks) == 2 % Split of the names. The function strtok could also be used to split % the string into parts. first = name(1:blanks(1)-1); middle = name(blanks(1)+1:blanks(2)-1); last = name(blanks(2)+1:length(name)); first(1) = upper(first(1)); middlei = upper(middle(1)); last(1) = upper(last(1)); fprintf('%s, %s %s.n',last, first, middlei) else fprintf('Too many names or spaces in %snProgram endn',name) End ---------------------------------------- 12.010 HW 05 Q2: Enter Name (first middle last) thomas abram herring Herring, Thomas A. programminghomeworkhelp.com
  • 11. Question 3: The solution to this problem is also quite easy in Matlab. We use the OED 45 1st order differential equation solver. To use this function we also have a function that computes the acceleration at the bike and another function that is the event detector that determines when the bike reaches 10 km distance. For ease of coding, the variables that control the characteristics of the bike are saved as globals. We also use an input dialog box to both set the defaults and allow the user to change the values at runtime. Also included in the solution is an animation and plot of the motion of the bike. To have the animation runs smoothly we change the output interval of the differential equation solver so that we generate more points then those that given in the standard 100 seconds separated values. There are some interesting bugs in Matlab for plotting the velocity vectors. The quiver option is used for this plot but in the current release of Matlab the arrowheads are extremely large and are turned off in the plots. Also the automatic scaling of the vectors does not generate reasonable length vectors, and so in these plots we manually set the scale factor. To compute the energy used during a bike ride, we simply added the derivative of the energy to the differential equations. This way the total energy was integrated automatically in the solution and could be output to the table as shown below. programminghomeworkhelp.com
  • 12. The solution M-files are: % 12.010 HW 05 Q 3: Bike simulator % % This script m-file simulates the motions of a paper plane being % influenced by gravity, lift and drag % % There are many ways to solve this problem and we will use the Matlab ODE % solvers with event detection (the event in this case is the z-value % hitting zero). % global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength terr % Define these globals so that they will be accessible in the acceleration routine global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength terr % Define these globals so that they will be accessible in the acceleration routine Grav = -9.8 ; % m/sec^2 Rho = 1.226; % kg/m^3 %----- Get the inout that we need ----- prompt = {'Track Grade (m/m)', 'Track Asin (m)', 'Track Bcos (m)', 'Wavelegth (km)','Track Length (km)','Mass (kg)', ... 'Rider Area (m^2)', 'Drag Coefficient','Rolling coefficient','Power programminghomeworkhelp.com
  • 13. (watts)','Max Force (N)', ... 'Output Interval (sec)','Error (mm)'}; title = 'Track and Bike Parameters'; nlines = 1; defaults = {'0.001','5.0','0.0','2.0','10.0','80.0','0.67','0.9','0.007','100.0','20','100','1'}; % Get user inputs and save in the appropriate valuyes result = inputdlg(prompt,title,nlines, defaults,'on'); % Slope = eval(result{1}); As = eval(result{2}); Bs = eval(result{3}); Lambda = eval(result{4})*1000.0 ; % Convert to meters TLength = eval(result{5})*1000.0 ; % Convert to meters Mass = eval(result{6}) ; Area = eval(result{7}) ; Cd = eval(result{8}) ; Cr = eval(result{9}) ; Pr = eval(result{10}) ; Fr_Max = eval(result{11}) ; tstep = eval(result{12}) ; terr = eval(result{13})/1000 ; % convert height error to m programminghomeworkhelp.com
  • 14. % % Set the ODE options. hit is the name of an m-file which will detect when % we hit the ground. options = odeset('AbsTol',[terr terr terr terr 100],'Events','bikehit'); % Set up the initial conditions y0 = [0.0; Bs ; 0.0 ; 0.0; 0.0]; % Set the maximum integration time to 5000 seconds. In a more general % problem we should check to see of this is enough time tmax = 5000; % Solve the ODE fprintf('n Starting new run n'); [t,y,te,ye,ie] = ode45(@bikeacc,[0:tstep:tmax],y0,options); % % Output the final results fprintf('---------------------------------------------------------------------n'); fprintf('12.010 HW 05 Q 3: Bike simulationn'); % Output table of values fprintf('--------------------------------------------------------------------------n') fprintf(' Time X pos Z pos X Vel Z Vel Energy n') fprintf(' (sec) (m) (m) (m/s) (m/s) (Joules)n') fprintf(' %9.3f %12.4f %10.4f %10.4f %10.4f %12.2fn',[t,y(:,1:5)]'); programminghomeworkhelp.com
  • 15. fprintf('-------------------------------------------------------------------------------------------------n') fprintf(‘ Time : %8.3f, Velocity %6.4f %6.4f n',te,ye(3),ye(4)) fprintf('Energy used: %12.2f Joules, %8.2f kcalsn', ye(5), ye(5)*0.2388e-3); % Now animate (make as function) %banimate(t,y); % Re-run the solution for the animation [ta,ya,tae,yae,iae] = ode45(@bikeacc,[0:10.0:te],y0,options); fprintf('nTo show animation: banimate(ta,ya)n'); % function dy = bikeacc(t, y) % acc: Computes accelerations including drag (Cd), rolling (Cr) and % and gravity % y contains, [x z xdot zdot energy] and dy is the time derivative % global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength % Define these globals so that they will be accessible in the acceleration routine dy = zeros(5,1); % a column vector % % get the road slope for our current x position. programminghomeworkhelp.com
  • 16. theta = atan(Slope + As*cos(2*pi*y(1)/Lambda)*2*pi/Lambda - Bs*sin(2*pi*y(1)/Lambda)*2*pi/Lambda); % % Compute forces: Assuming bike remains on road surface % Drag: vmag = sqrt(y(3)^2+y(4)^2); thetad = atan2(y(4),y(3)); dxd = -Rho*Cd*vmag^2*Area*cos(thetad)/(2*Mass); dzd = -Rho*Cd*vmag^2*Area*sin(thetad)/(2*Mass); dxr = +Grav*Cr*cos(theta) ; dzr = +Grav*Cr*sin(theta) ; % % Get rider force Fr_mag = Fr_Max ; if ( vmag > 0 ) Fr_mag = Pr/vmag ; end if ( Fr_mag > Fr_Max ) Fr_mag = Fr_Max ; end height = Slope*y(1) + As*sin(2*pi*y(1)/Lambda) + Bs*cos(2*pi*y(1)/Lambda); %if ( y(2) > height + 0.1 ) Fr_mag = 0; end dxp = Fr_mag*cos(theta)/Mass ; dzp = Fr_mag*sin(theta)/Mass ; % % Normal force from surface (Grav is a negative value) dxn = Grav*cos(theta)*sin(theta); programminghomeworkhelp.com
  • 17. dzn = -Grav*cos(theta)^2; % Get the curvature dy2dx2 = -As*sin(2*pi*y(1)/Lambda)*(2*pi/Lambda)^2 - Bs*cos(2*pi*y(1)/Lambda)*(2*pi/Lambda)^2; IRc = (dy2dx2)/(1+theta^2)^(3/2); dxc = vmag^2*sin(theta)*IRc; dzc = vmag^2*cos(theta)*IRc; %fprintf(' %5.2f %9.5f %9.5f %5.2f %6.4f %10.1f n',vmag, dxc, dzc, dxd, dzd, Rc) % % Update the dy velocity acceleration vector dy(1) = y(3); dy(2) = y(4); dy(3) = dxd + dxr + dxp + dxn + dxc ; dy(4) = dzd + dzr + dzp + dzn + dzc + Grav ; dy(5) = Fr_mag * vmag; function [value,isterminal,direction] = bikehit(t,y) % Locate the time when height passes through zero in a decreasing direction % and stop integration. global Grav Rho Mass Cd Cr Area Slope As Bs Lambda Pr Fr_Max TLength value = y(1)-TLength; % detect when end is 0. isterminal = 1; % stop the integration direction = 1; % negative direction programminghomeworkhelp.com
  • 18. function banimate(t,y) % Function to animate the motion qs = 50; num = length(t); hf1 = figure(1); set(hf1, 'Position',[10 100 750 400]); hold off; pc = plot(y(1,1),y(1,2),'o','MarkerFaceColor','r','EraseMode','xor'); hold on pq = quiver(y(1,1),y(1,2),y(1,3),y(1,4),0); xm = y(num,1)*1.01; ym = max(y(:,2))*1.01; xs = min(y(:,1))*1.01; ys = min(y(:,2))*1.01; xlim([xs xm]); ylim([ys ym]); xlabel('Distance (m)'); ylabel('Height (m)'); pt = text(xm/100,ym*0.96,'Time 0.00 s'); %daspect([1 1 1]); drawnow; % Release 2011a of Matlab has some strange scaling in quiver and so we % manually set properities that should be automatically set. Also arrow % heads are very wide so we turn them off here. for i = 1: num % Replace the data point set(pc,'XData',y(i,1),'YData',y(i,2)); delete(pq); pq = quiver(y(i,1),y(i,2),y(i,3),y(i,4),qs); set(pq,'ShowArrowHead','off','AutoScaleFactor',qs,'AutoScale','on'); otext = sprintf('Time %6.1f s',t(i)); programminghomeworkhelp.com
  • 19. set(pt,'String',otext); drawnow; end plot(y(:,1),y(:,2),'g'); %% hf2 = figure(2); set(hf2, 'Position',[760 100 350 200]); hold off; pc = plot(y(:,1),y(:,2),'o','MarkerFaceColor','r','EraseMode','normal'); hold on pq = quiver(y(:,1),y(:,2),y(:,3),y(:,4)); set(pq,'ShowArrowHead','off'); xlabel('Distance (m)'); ylabel('Height (m)'); axis tight; ylim([-10 15]); %% hf3 = figure(3); set(hf3, 'Position',[760 380 350 200]); plot(t,(sqrt(y(:,3).^2+y(:,4).^2))); xlabel('Time (sec)'); ylabel('Total Velocity (m/s)'); The table and figures below show the results for the default solution. programminghomeworkhelp.com
  • 21. Figure 2: Trajectory of the bike along with vectors showing its velocity (green lines). Due to poor scaling in Matlab, no arrowheads are shown. Figure 3: Velocity as a function of time for the bike. programminghomeworkhelp.com