SlideShare a Scribd company logo
For any help regarding Computational Methods Of Scientific Programming Assignment Help
Visit : https://www.programminghomeworkhelp.com/,
Email : support@programminghomeworkhelp.com or
call us at - +1 678 648 4277
programminghomeworkhelp.com
Question (1): (a) Write Mathematica NoteBook which generates a table of error function (erf) and its derivatives for
real arguments (z) between -‐3and 3 in steps of 0.25. The error function is defined by the equation below (but is
rarely evaluated by performing the integration).
(see http://mathworld.wolfram.com/Erf.html for information the error function )
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 NoteBook and give an example of the output.
(b) How would you change this NoteBook if 10 significant digits were required? Mathematica NoteBook
should also be supplied
Question (2):
Write a NoteBook 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
NoteBook should not be specific to the lengths of your name (ie., the NoteBook should work with
anyone’s name.
As an example. An input of thomas abram herring would generate:
Herring, Thomas A.
Question (3): Write a Mathematica NoteBook 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
H(x)  Sx  Asin(2 x / )  Bcos(2 x / )
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:
Wind Drag
Rolling Drag
Fd 1/2ArCd V2
Fr  MrgCr
programminghomeworkhelp.com
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
Rider force Fr  Pr /V
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). Your NoteBook
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
NoteBook can assume a constant power scenario and constant force at low velocities.
As a test of your NoteBook use the following constants to compute:
(a)Time to travel and energy used to travel 10 km along a path specified by
S=0.01, 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 NoteBook which plots the velocity of the bike as a function of time and
position along the path.
programminghomeworkhelp.com
Assume the following values
Cd = 0.9
Cr = 0.007
Ar = 0.67 m2
r = 1.226 km/m3
g = 9.8 m/s2
Mr = 80 kg
In this case, the Mathematica NoteBook will not be of the type used for fortran and
C/C++. Look at the documentation on NDSolve for this problem.
Your answer to this question should include:
(a)The algorithms used and the design of your NoteBook
(b)The Mathematica NoteBook with your code and solution (I run your NoteBook).
(c)The results from the test case above.
programminghomeworkhelp.com
This latest version of Mathematica has some issues with copying and pasting
equations and graphics from Microsoft Word. It also seems not to be able to
reproduce subscripts and superscripts from word, which previously was able to
do. It is not clear if the incompatibility is from the Microsoft Word or the
Mathematica side. This is another indication of how changes in versions of
software can have unintended consequences.
(Question 1): (a) Write Mathematica NoteBook 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).
(see http://mathworld.wolfram.com/Erf.html for information the error function
)
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 NoteBook and give an example
of the output.
(b) How would you change this NoteBook if 10 significant digits were required?
Mathematica NoteBook should also be supplied
● Solution: Given that the error function is defined in Mathematica themost tricky part of the this problem is
formarting the ourput. There are many ways to approach the output problem.
programminghomeworkhelp.com
Off@General::spell1D;
H* Stops message about head looking like a command*L head =
8"Argument", "Erf@zD", "dErf@zDêdz"<; derf@arg_D := 2 ê Sqrt@PiD *
Exp@-x^2D;
ents =
Table@8N@SetAccuracy@x, 10D, 3D, In[1]:=
N@SetAccuracy@Erf@xD, 10D, 6D, N@SetAccuracy@derf@xD, 6D, 6D<,
8x, -3, 3, 0.25<D;
full = Insert@ents, head, 1D; Out[6]//TableForm=
TableForm@full, TableAlignments Ø RightD
Argument Erf@zD dErf@zDêdz
-3.00 -0.999978 0.00014
-2.75 -0.999899 0.00059
-2.50 -0.999593 0.00218
-2.25 -0.998537 0.00714
-2.00 -0.995322 0.02067
-1.75 -0.986672 0.05277
-1.50 -0.966105 0.118930
-1.25 -0.922900 0.23652
-1.00 -0.842701 0.41511
-0.750 -0.711156 0.64293
-0.500 -0.520500 0.87878
-0.250 -0.276326 1.06001
0.µ 10-10 0.µ 10-10 1.12838
0.250 0.276326 1.06001
0.500 0.520500 0.87878
0.750 0.711156 0.64293
1.00 0.842701 0.41511
1.25 0.922900 0.23652
1.50 0.966105 0.118930
1.75 0.986672 0.05277
2.00 0.995322 0.02067
2.25 0.998537 0.00714
2.50 0.999593 0.00218
2.75 0.999899 0.00059
3.00 0.999978 0.00014
(b) Output of table to 10 deciminal places.
programminghomeworkhelp.com
Off@
General::spell1D
; H
* Stops message about head looking like a command*L head =8"Argument",
"Erf@
zD
", "dErf@
zD
êdz"<;
In[22]:=
derf@
arg_D := 2 êSqrt@
PiD* Exp@
-x^2D
;
ents =Table@
8
N@
SetAccuracy@
x, 10D
, 3D
, N@
SetAccuracy@
Erf@
xD
, 10D
, 10D
, Out[26]//TableForm=
N@SetAccuracy@derf@xD, 10D, 10D<, 8x, -3, 3, 0.25<D;
full =Insert@
ents, head, 1D
; TableForm@full, TableAlignments Ø RightD
Argument Erf@zD dErf@zDêdz
-3.00 -0.999977910 0.000139253
-2.75 -0.999899378 0.0005862772
-2.50 -0.999593048 0.002178284
-2.25 -0.998537283 0.0071423190
-2.00 -0.995322265 0.0206669854
-1.75 -0.986671671 0.0527749959
-1.50 -0.9661051465 0.1189302892
-1.25 -0.9229001283 0.2365211224
-1.00 -0.8427007929 0.415107497
-0.750 -0.7111556337 0.642931069
-0.500 -0.5204998778 0.878782579
-0.250 -0.2763263902 1.060014129
0.µ 10-10 0.µ 10-10 1.128379167
0.250 0.2763263902 1.060014129
0.500 0.5204998778 0.878782579
0.750 0.7111556337 0.642931069
1.00 0.8427007929 0.415107497
1.25 0.9229001283 0.2365211224
1.50 0.9661051465 0.1189302892
1.75 0.986671671 0.0527749959
2.00 0.995322265 0.0206669854
2.25 0.998537283 0.0071423190
2.50 0.999593048 0.002178284
2.75 0.999899378 0.0005862772
3.00 0.999977910 0.000139253
programminghomeworkhelp.com
period after the middle initial. If the names start with lower case letters, then these should be
capitalized. The NoteBook should not be specific to the lengths of your name (ie., the NoteBook
should work with anyone’s name.
As an example. An input of thomas abram herring
would generate:
Herring, Thomas A.
● This problem is not too bad to solve. This solution works in >5.0 Mathematica and does
explicitly some things such as splitting a string apart that are now Mathemat- ica commands
(StringSplit).
programminghomeworkhelp.com
In[27]:=
H
* Define a function that will convert chararacter of a string to upper case *L
confirst@a_D := StringReplacePart@a, ToUpperCase@StringTake@a, 81<DD,81, 1<D;
H
* Get the name from the user*L
inname =InputString@"Enter Name Hfirst, middle, lastL "D;
H
* Convert whole string to lower case*L fullname =
ToLowerCase@innameD;
H
* Now get the list of blanks in the string*L posblanks =
StringPosition@fullname, " "D;
H
* Get the position of first blank*L
posfirst = Extract@
Extract@
posblanks, 1D
, 1D
; firstname =
StringTake@
fullname, posfirst- 1D
;
firstname = confirst@
firstnameD
; H
* Use our confirst routine *L H
* Get Middle Name
*L
posmid = Extract@
Extract@
posblanks, 2D
, 1D
;
midinit = StringTake@fullname, 8posfirst+1, posfirst +1<D;midinit =
confirst@midinitD;
H
* Get Last Name *L
lastname = StringTake@fullname, 8posmid+1, StringLength@fullnameD<D; lastname =
confirst@lastnameD;
H
* Output the string *L
finalname = lastname <> ", " <> firstname <> " " <> midinit <> "."; outline = "Input
name " <> inname <> " converted to: " <> finalname; H
* Output the results*L
Print@outlineD;
Input name thomas abram herring converted to: Herring, Thomas A.
Write a Mathematica NoteBook 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
H(x)  Sx  Asin(2x /)  B cos(2x / )
programminghomeworkhelp.com
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:
Wind Drag Rolling
Drag
Fd 1/2ArCdV 2
Fr  MrgCr
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
Rider force Fr  Pr /V
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). Your NoteBook 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 NoteBook can assume a
constant power scenario and constant force at low velocities.
As a test of your NoteBook 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
programminghomeworkhelp.com
and a maximum force available of 20N.
(b)
(c)
The position and velocity of the bike tabulated at a 100-‐second interval. Add
graphics to your NoteBook 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
Ar = 0.67 m2
 = 1.226 kg/m3
g = 9.8 m/s2
Mr = 80 kg
In this case, the Mathematica NoteBook will not be of the type used for fortran and C/C++. Look at the
documentation on NDSolve for this problem.
Your answer to this question should include:
(a) The algorithms used and the design of your NoteBook
(b)The Mathematica NoteBook with your code and solution (I run your NoteBook).
(c) The results from the test case above.
● There are several ways of approaching this problem and two solution are presented below. The problem itself is
dvided into a number of cells that allow parts of prob- lem to be re-execuated. There two basic steps to the
solution:
(1)Use NDSolve to solve the second order differential equation that describes the problem. The solution
effectively becomes an equation that returns values at any specified time.
programminghomeworkhelp.com
(2) Use FindRoot to determine when the bike has reached the end of track.
cr = 0.007;
area
mass
● Set up the defaults first. This cell should be evaluated
Clear@t, x, xd, hx, vx, xp, xd, th, daccD; cd =
0.90 ;
H*Print@"Parameter cd ",cdD*L
= 0.67; H* m^2 *L
= 80; H* kg *L
prider = 100; H* Power Watts*L
fmax = 20;
slope = 0.001;
as = 5.0;
bs = 0.0;
lambda = 2000;
tracklen = 10 000;
outint = 100.0;
H* Define the acceleration functions we will need*L grav =
9.8 ;
rhoair = 1.226; Print@"Default Values
set"D
Default Values set
● Now allow the user to enter values of there own. This cell does not need to be evaluated if
the default values are desired.
programminghomeworkhelp.com
In[82]:=
Input@"Drag Coefficient ", cdD; Input@"Rolling friction coefficient ",
crD;
tracklen = Input@"Length of track HkmL ", tracklen ê 1000D *
1000.0;
slope = Input@"Track slope ", slopeD; as = Input@"Sin
Amplitude HmL ", asD; bs = Input@"Cos Ampliude Hm L", bsD;
lambda = Input@"Periodic wavelength HkmL ", lambda ê 1000D *
1000.0;
mass = Input@"Rider+Bike Mass HkgL ", massD; area =
Input@"Rider Area Hm^2L ", areaD;
cd =
cr =
outint = Input@"Output interval HsL", outintD;
o Now set up the force model equations
In[92]:=
theta@xp_D :=
ArcTan@slope + as * Cos@2 * Pi * xp ê lambdaD * 2 * Pi ê lambda -
bs * Sin@2 * Pi * xp ê lambdaD * 2 * Pi ê lambdaD htrack@xp_D := slope * xp +
as * Sin@2 * Pi * xp ê lambdaD +
bs * Cos@2 * Pi * xp ê lambdaD;
H* Second derivative of surface for computing cenripical
acceleration *L
dy2dx2@xp_D := - as * Sin@2 * Pi * xp ê lambdaD * H2 * Pi ê lambdaL^2 -
bs * Cos@2 * Pi * xp ê lambdaD * H2 * Pi ê lambdaL^2; vmag@xd_, zd_D :=
Sqrt@xd^2 + zd^2D;
programminghomeworkhelp.com
programminghomeworkhelp.com
H* Acceleration due to drag *L
- rhoair * vmag@xd, zdD * area * cd *
- rhoair * vmag@xd, zdD * area * cd *
dragx@xd_, zd_D :=
xd ê H2 * massL;
dragz@xd_, zd_D :=
zd ê H2 * massL;
H* Rolling
rollx@xp_D
rollz@xp_D
H* Gravity
gravx@xp_D
gravz@xp_D
force. This act along surface *L
:= - grav * cr * Cos@theta@xpDD;
:= - grav * cr * Sin@theta@xpDD;
force acting perpendicular to surface *L
:= -grav * Cos@theta@xpDD * Sin@theta@xpDD;
:= +grav * Cos@theta@xpDD^2;
H* Centripetal acceleration *L
H* Could divide by Sqrt@H1+Tan@theta@xpDD^2L^3DD
factor to curvature term. This change does not seem
to make solution closer to track shape*L
centx@xp_,xd_,zd_D :=
Hxd^2+ zd^2L* Sin@theta@xpDD* dy2dx2@xpD; centz@xp_,xd_,zd_D :=
Hxd^2+ zd^2L* Cos@theta@xpDD* dy2dx2@xpD;
H* This commented code has expression for radius of curvature
centx@xp_,xd_,zd_D :=
Hxd^2+zd^2L*Sin@theta@xpDD*
dy2dx2@xpDêSqrt@H1+Tan@theta@xpDD^2L^3D; centz@xp_,xd_,zd_D :=
Hxd^2+zd^2L*Cos@theta@xpDD*
dy2dx2@xpDêSqrt@H1+Tan@theta@xpDD^2L^3D;
*L
H* To see the effects of the centripetal force, remove the comments below
centx@xp_,xd_,zd_D :=0;
centz@xp_,xd_,zd_D :=0;
*L
H* Now the rider force *L
ridrx@xp_,xd_,zd_D :=
HMin@If@vmag@xd,zdD> 0, priderêvmag@xd,zdD,fmaxD, fmaxDêmassL*
Cos@theta@xpDD;
ridrz@xp_,xd_,zd_D :=
HMin@If@vmag@xd,zdD> 0, priderêvmag@xd,zdD,fmaxD, fmaxDêmassL*
Sin@theta@xpDD;
Print@AccelerationfunctionsSetD
AccelerationfunctionsSet
● The following cell can be used to test that the acceleration functions above gener- ate numeric
results when called with distance and velocity. This test is useful if NDSolve does not return
answer.
programminghomeworkhelp.com
In[121]:=
dx = 1500.; txv = 2.0; tzv = 0.01; Print@"Slope ",
theta@dxD, " 2nd derivative ",
dy2dx2@dxD, " Height ", htrack@dxDD
Print@"Drag X ", dragx@txv, tzvD, " Z ", dragz@txv, tzvDD
Print@"Roll X ", rollx@dxD, " Z ", rollz@dxDD Print@"Gravity
X ", gravx@dxD, " Z ", gravz@dxDD Print@"Centripetal X ",
centx@dx, txv, tzvD, " Z ",
centz@dx, txv, tzvDD
Print@"Rider X ", ridrx@dx, txv, tzvD, " Z ",
ridrz@dx, txv, tzvDD
Slope 0.001 2nd derivative 0.000049348 Height -3.5
Drag X -0.0184822 Z -0.0000924109 Roll X -0.0686 Z -
0.0000686 Gravity X -0.00979999 Z 9.79999
Centripetal X 1.97397 µ 10- 7 Z 0.000197397
Rider X 0.25 Z 0.00025
● Now set up the solution for NDSolve. There are two equations in the x and z accel- erations
and initial conditions for x and z and x' and z' at time zero. The solution is set to solve for a
maximum of 10000 seconds. This is OK for the standard case but may need to be modified
for other longer running cases.
The evaluaton of the solution is saved for x and z positions and z and z velocities.
(NDSolve contains examples of setting up these solutions.
We can then find the length of the time need by solving the equation xp[t]-tracklen
== 0. This is not with FindRoot.
programminghomeworkhelp.com
In[177]:=
solution =
NDSolve@
8x''@tDã ridrx@x@tD,x'@tD,z'@tDD+ dragx@x'@tD,z'@tDD+
rollx@x@tDD+ gravx@x@tDD+ centx@x@tD,x'@tD,z'@tDD,
z''@tDã ridrz@x@tD,x'@tD,z'@tDD+ dragz@x'@tD,z'@tDD+
rollz@x@tDD+ gravz@x@tDD- grav+
centz@x@tD,x'@tD,z'@tDD, x@0D== 0,z@0Dã 0, x'@0Dã 0,z'@0Dã 0<,8x,z<,8t,0,10000<D;
xp@t_D := First@Evaluate@x@tD ê. solutionDD; zp@t_D:= First@Evaluate@z@tDê.solutionDD;
xv@t_D:= First@Evaluate@x'@tDê.solutionDD; zv@t_D:= First@Evaluate@z'@tDê.
solutionDD;
H* Compute the error in the distance *L
endt = t ê. FindRoot@xp@tD- tracklenã 0,8t,1,3000.0<D;
H* Now integrate to get work done *L
work = NIntegrate@mass* Sqrt@xv@tD^2+ zv@tD^2D*
Sqrt@ridrx@xp@tD,xv@tD,zv@tDD^2+
ridrz@xp@tD,xv@tD,zv@tDD^2D,8t,0,endt<, AccuracyGoalØ 4D;
Print@"Time to reach end of track ",endt," sec, Speed ", xv@endtD," mês"D;
Print@"Work done ",work," Joules, ",workê4.1868ê10^3, " kcal"D;
NIntegrate::ncvb :
NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t near 8t<= 8678.279<. NIntegrate obtained
174398.48726962117`
and 0.39321119853291564` for the integral and error estimates. à
Time to reach end of track 2255.17 sec, Speed 2.65009 mês Work done 174398. Joules, 41.6544 kcal
● The case above gives an example of how tricky Mathematica can be in telling you what it is actually doing.
In the integration above for work a numerical rounding error message is printed. The message suggests
there is some problem around 678 seconds. The cell below divides the calculation into 2 parts normally split
at around 678 seconds and in this case no numerical error warning is printed. It’s not at all clear why the
program is behaving this way.
programminghomeworkhelp.com
In[166]:=
tt = 678.279;
worksplit =
NIntegrate@mass * Sqrt@xv@tD^2 + zv@tD^2D *
Sqrt@ridrx@xp@tD, xv@tD, zv@tDD^2 +
ridrz@xp@tD, xv@tD, zv@tDD^2D, 8t, 0, tt<D +
NIntegrate@mass * Sqrt@xv@tD^2 + zv@tD^2D *
Sqrt@ridrx@xp@tD, xv@tD, zv@tDD^2 +
ridrz@xp@tD, xv@tD, zv@tDD^2D, 8t, tt, endt<D; Print@"Work
computed in one step ", work,
" and split at time ", tt, " " , worksplit,
". Difference in results ", work - worksplitD;
Work computed in one step 174 399. and split at time
678.279 174 399.. Difference in results 0.
●Final output for version A (full solutions)
In[185]:=
Print@"12.010 HW 4: Mathematica Bike Problem"D;
Print@"Solution Parameters"D;
Print@"Track Length ", tracklen ê 1000.0, " km"D;
Print@"Track Slope ", slope, " Sin Cos ", as, " ",
bs, " m, Lambda ", lambda ê 1000., " km"D; Print@"Rider
Power ", prider, " Watts, Max Force ",
fmax, " N"D;
Print@"Time to reach end of track ", endt, " sec, Speed ",
xv@endtD, " mês"D
Print@"Work done by rider ", work, " Joules, ", work ê
4.1868 ê 10^3, " kcal" D
programminghomeworkhelp.com
12.010 HW 4: Mathematica Bike Problem
Solution Parameters Track Length 10. km
Track Slope 0.001 Sin Cos 5. 0. m, Lambda 2. km Rider Power 100
Watts, Max Force 20 N
Time to reach end of track 2255.17 sec, Speed 2.65009 mês Work done by
rider 174 398. Joules, 41.6544 kcal
programminghomeworkhelp.com
● Add some graphics to the results: Velocity versus time, Z position versus X posi- tion, and
difference from track shape. The latter plot shows how well our integra- tion matched the actual
shape of the track.
In[241]:=
Plot@ xv@tD, 8t, 0, endt<,
AxesLabel Ø 8"Time HsecL", "Velocity HmêsL"<D
ParametricPlot@ 8xp@tD ê 1000 , zp@tD<, 8t, 0, endt<, AxesLabel Ø 8"X
position HkmL", "Z positionHmL"<, AspectRatio Ø 1 ê 1D
ParametricPlot@ 8xp@tD ê 1000 , Hzp@tD - htrack@xp@tDDL * 1000.<,
8t, 0, endt<,
AxesLabel Ø 8"X position HkmL", "Error in Z HmmL"<, AspectRatio Ø 1 ê
1D
Out[241]=
500 1000 1500 2000
Time
3
2
1
4
Velocity HmêsL
7
6
5
programminghomeworkhelp.com
Out[242]=
2 4 6 8 10 X position
5
10
Z positionHmL
programminghomeworkhelp.com
2 4 6 8 10
X position
- 0.4
- 0.3
- 0.1
Out[243]=
- 0.2
0.1
Error in Z HmmL
0.2
-0.5
● We now use table and table form to have to put the positions and velocities as
a function of the interval selected by the user. (The default interval is 100
seconds). To generate the table with 100s output, and to add the final value, we
generate the table in two parts and save the table in a list called outlst. We use the
append function to join the two tables together.
programminghomeworkhelp.com
In[274]:=
outlst = Table@8t, xp@tD, zp@tD, xv@tD, zv@tD<,
8t, 0, endt, outint<D;
H* Now add the final entry to the tabe; *L
outlst =
Append@outlst,
Transpose@Table@8t, xp@tD, zp@tD, xv@tD, zv@tD<,
8t, endt, endt, outint<DDD;
TableForm@outlst,
TableHeadings Ø
8None, 8"Time HsL", "X Pos HmL", "Z pos HmL",
"X Vel HmêsL", "Z Vel HmêsL"<<D
Out[276]//TableForm=
Time HsL
0
X Pos HmL
0.
Z pos HmL
0.
X Vel HmêsL
0.
Z Vel HmêsL
-5.29396µ 10-23
100 79.9901 1.32329 1.48869 0.0241386
200 306.763 4.41341 3.36696 0.0335387
300 826.797 3.41531 6.79761 -0.0845564
400 1513.81 -3.48135 5.87698 0.00988077
500 1951.68 1.19559 2.95947 0.0489105
600 2202.42 5.17194 2.65422 0.0361969
700 2608.52 7.32075 5.8297 -0.0247871
800 3292.9 -0.685554 6.88819 -0.0586485
900 3834.83 1.35511 3.88251 0.0568391
1000 4117.37 5.91931 2.35353 0.0368374
1100 4428.12 9.30101 4.53331 0.0204786
1200 5046.56 4.31778 7.24973 -0.105412
1300 5681.7 1.47426 4.97372 0.0471862
1400 6035.25 6.58758 2.48085 0.0412101
1500 6294.17 10.2845 3.32052 0.0347469
1600 6803.7 9.69517 6.71443 -0.0793262
1700 7493.54 2.49435 5.98646 0.00407604
1800 7941.44 7.0264 3.03341 0.0498764
1900 8193.43 11.0479 2.60451 0.0361917
2000 8588.77 13.3952 5.72489 -0.0190286
2100 9269.22 5.52648 6.96317 -0.0655712
2200 9821.37 7.16001 3.99206 0.0570797
2255.17 10000. 9.99951 2.65009 0.0442763
programminghomeworkhelp.com
tance along the sirface. These could be derived given that we have the eqautions. A
simpler solution to solve for the horizontal motion and compute the z-motion consistent
wth staying on the track. The z-motion is needed because drag and rider force depend on
the total velocity not just the horizontal velocity.
We use the same constants above but we re-define the accerations and NDSolve here.
In[284]:=
theta@xp_D :=
ArcTan@slope + as * Cos@2 * Pi * xp ê lambdaD * 2 * Pi ê lambda -
bs * Sin@2 * Pi * xp ê lambdaD * 2 * Pi ê lambdaD
H* Get total velocity given running on track *L
vtot@xd_, xp_D := Sqrt@xd^2 + Hxd * Tan@theta@xpDDL^2D;
dacc@xd_, xp_D := -cd * rhoair * vtot@xd, xpD^2 *
area ê H2 * massL;
racc@th_D := - grav * cr * Cos@thD; facc@xd_, xp_D
:=
Min@If@ vtot@xd, xpD > 0, prider ê vtot@xd, xpD, fmaxD, fmaxD ê
mass
gacc@th_D := - grav * Sin@thD; Print@"1-D
accelerations set"D
1-D accelerations set
programminghomeworkhelp.com
● Alternative solution, Here we solve the one dimensional problem which is basi-
cally the roller coaster solution that keeps the bike on the ground. In the Fortran and
C-versions we computed the forces along the sloped surface and integrated
horizontal motions from the motion along the slope. If a similar approach is fol-
lowed here, then we need expressions for height and slope as functions of the dis-
H* Set up differential equations to be be solved, x@tD is
horizontal position,
There is still a problem here with along track versus horizontal
distance
Here we use y for the dependent variable*L solnb =
NDSolve@ 8y''@tD ã
Hdacc@y'@tD, y@tDD + gacc@theta@y@tDDD +
racc@theta@y@tDDD + facc@y'@tD, y@tDDL *
Cos@theta@y@tDDD,
y@0D ã 0, y'@0D ã 0.0<, y, 8t, 0.0, 10 000.0<,
AccuracyGoal Ø 10D;
py@t_D := Evaluate@y@tD ê. solnbD; vy@t_D :=
Evaluate@y'@tD ê. solnbD;
H* Compute the error in the distance *L
endb = t ê. FindRoot@py@tD - tracklen ã 0 , 8t, 1, 3000.0<D; work =
NIntegrate@mass * facc@First@vy@tDD, First@py@tDDD *
vtot@First@vy@tDD, First@py@tDDD, 8t, 0, endt<D; Print@"Time to
reach end of track ", endb, " sec, Speed ",
First@vy@endtDD, " mês"D;
Print@"Work done ", work, " Joules, ", work ê 4.1868 ê 10^3, " kcal" D;
Time to reach end of track 2255.05 sec, Speed 2.64848 mês Work
done 174 405. Joules, 41.6558 kcal
Plot@8vy@tD, Sqrt@xv@tD^2 + zv@tD^2D<, 8t, 0, endb<, PlotRange
Ø All,
AxesLabel Ø 8"Time HsecL", "Velocity HmêsL"<D
Plot@Hvy@tD - Sqrt@xv@tD^2 + zv@tD^2DL * 1000, 8t, 0, endb<, PlotRange
Ø All,
AxesLabel Ø 8"Time HsecL", "Diff Vel HmmêsL"<D
In[311]:=
programminghomeworkhelp.com
Out[311]=
500 1000 1500 2000
3
2
1
4
Velocity HmêsL
7
6
5
Out[312]=
500 1000 1500 2000
Time
- 4
- 2
2
4
Diff Vel HmmêsL
6
● Now output table of values
programminghomeworkhelp.com
In[308]:=
outl1d = Table@8t, py@tD, vy@tD<, 8t, 0, endb, outint<D;
H* Now add the final entry to the tabe; *L
outl1d =
Append@outl1d,
Transpose@Table@8t, py@tD, vy@tD<,
8t, endb, endb, outint<DDD;
TableForm@outl1d,
TableHeadings Ø
8None, 8"Time HsL", "X Pos HmL", "X Vel HmêsL"<<D
Out[310]//TableForm=
Time HsL X Pos HmL X Vel HmêsL
0 0. 0.
100 80.0296 1.48938
200 306.907 3.36857
300 827.102 6.79856
400 1514.08 5.87554
500 1951.82 2.95863
600 2202.58 2.65548
700 2608.89 5.83165
800 3293.34 6.88692
900 3835.08 3.8804
1000 4117.54 2.35409
1100 4428.5 4.537
1200 5047.16 7.25006
1300 5682.12 4.97145
1400 6035.47 2.48028
1500 6294.5 3.32362
1600 6804.39 6.7169
1700 7494.16 5.98318
1800 7941.75 3.03121
1900 8193.74 2.6065
2000 8589.47 5.72868
2100 9270.08 6.96082
2200 9821.86 3.98801
2255.05 10000. 2.65031
programminghomeworkhelp.com

More Related Content

What's hot (20)

PPTX
Computer Science Assignment Help
Programming Homework Help
 
PDF
Programming with matlab session 1
Infinity Tech Solutions
 
PDF
Oct.22nd.Presentation.Final
Andrey Skripnikov
 
PDF
Skyline queries
Victor Torras
 
PDF
International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
PPTX
An optimal and progressive algorithm for skyline queries slide
WooSung Choi
 
PPT
Cpphtp4 ppt 03
sanya6900
 
PPT
Intro to tsql unit 10
Syed Asrarali
 
PPT
Pointer
manish840
 
PDF
Dsp manual completed2
bilawalali74
 
PPTX
Computer Network Assignment Help
Computer Network Assignment Help
 
ODP
Scala as a Declarative Language
vsssuresh
 
PPS
Aae oop xp_06
Niit Care
 
PDF
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
vtunotesbysree
 
PPTX
Introduction to matlab
Khulna University
 
PPTX
Writing Fast MATLAB Code
Jia-Bin Huang
 
PDF
GATE Computer Science Solved Paper 2004
Rohit Garg
 
PPT
Csc1100 lecture14 ch16_pt2
IIUM
 
Computer Science Assignment Help
Programming Homework Help
 
Programming with matlab session 1
Infinity Tech Solutions
 
Oct.22nd.Presentation.Final
Andrey Skripnikov
 
Skyline queries
Victor Torras
 
International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
An optimal and progressive algorithm for skyline queries slide
WooSung Choi
 
Cpphtp4 ppt 03
sanya6900
 
Intro to tsql unit 10
Syed Asrarali
 
Pointer
manish840
 
Dsp manual completed2
bilawalali74
 
Computer Network Assignment Help
Computer Network Assignment Help
 
Scala as a Declarative Language
vsssuresh
 
Aae oop xp_06
Niit Care
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
vtunotesbysree
 
Introduction to matlab
Khulna University
 
Writing Fast MATLAB Code
Jia-Bin Huang
 
GATE Computer Science Solved Paper 2004
Rohit Garg
 
Csc1100 lecture14 ch16_pt2
IIUM
 

Similar to Computational Assignment Help (20)

PPTX
Computation Assignment Help
Programming Homework Help
 
PPTX
Computational Methods in Scientific Programming
Computer Science Homework Helper
 
PDF
MITCOE 2011-12 conm-submission
Ashutosh Katti
 
PDF
Mathematica tutorial 3
coolsumayya
 
PDF
Laboratory 7
Shafiul Omam
 
DOCX
© 2021 UniCourse Ltd. All Rights Reserved Page 1 of 9
LesleyWhitesidefv
 
PDF
C language numanal
aluavi
 
PDF
A simple numerical procedure for estimating nonlinear uncertainty propagation
ISA Interchange
 
PDF
Scilab is not naive
Scilab
 
PDF
Scilabisnotnaive
zan
 
PDF
Solving dynamics problems with matlab
Sérgio Castilho
 
PDF
Data mining assignment 5
BarryK88
 
PDF
Bisection method
Putera Shafiq
 
DOCX
Artifact3 allen
allent07
 
DOCX
Artifact3 allen
allent07
 
DOCX
Artifact3 allen
allent07
 
PDF
Assignment On Matlab
Miranda Anderson
 
PDF
A Survey Of Computational Physics Introductory Computational Science
Courtney Esco
 
PDF
Erin catto numericalmethods
oscarbg
 
PDF
Palm ch1
Heera Rawat
 
Computation Assignment Help
Programming Homework Help
 
Computational Methods in Scientific Programming
Computer Science Homework Helper
 
MITCOE 2011-12 conm-submission
Ashutosh Katti
 
Mathematica tutorial 3
coolsumayya
 
Laboratory 7
Shafiul Omam
 
© 2021 UniCourse Ltd. All Rights Reserved Page 1 of 9
LesleyWhitesidefv
 
C language numanal
aluavi
 
A simple numerical procedure for estimating nonlinear uncertainty propagation
ISA Interchange
 
Scilab is not naive
Scilab
 
Scilabisnotnaive
zan
 
Solving dynamics problems with matlab
Sérgio Castilho
 
Data mining assignment 5
BarryK88
 
Bisection method
Putera Shafiq
 
Artifact3 allen
allent07
 
Artifact3 allen
allent07
 
Artifact3 allen
allent07
 
Assignment On Matlab
Miranda Anderson
 
A Survey Of Computational Physics Introductory Computational Science
Courtney Esco
 
Erin catto numericalmethods
oscarbg
 
Palm ch1
Heera Rawat
 
Ad

More from Programming Homework Help (20)

PPTX
Data Structures and Algorithm: Sample Problems with Solution
Programming Homework Help
 
PPTX
Seasonal Decomposition of Time Series Data
Programming Homework Help
 
PPTX
Solving Haskell Assignment: Engaging Challenges and Solutions for University ...
Programming Homework Help
 
PPTX
Exploring Control Flow: Harnessing While Loops in Python
Programming Homework Help
 
PPTX
Java Assignment Sample: Building Software with Objects, Graphics, Containers,...
Programming Homework Help
 
PPTX
C Assignment Help
Programming Homework Help
 
PPTX
Python Question - Python Assignment Help
Programming Homework Help
 
PPTX
Best Algorithms Assignment Help
Programming Homework Help
 
PPTX
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
PPTX
Algorithm Homework Help
Programming Homework Help
 
PPTX
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
Programming Homework Help
 
PPTX
Algorithm Homework Help
Programming Homework Help
 
PPTX
Algorithms Design Assignment Help
Programming Homework Help
 
PPTX
Algorithms Design Homework Help
Programming Homework Help
 
PPTX
Algorithm Assignment Help
Programming Homework Help
 
PPTX
Algorithm Homework Help
Programming Homework Help
 
PPTX
C Homework Help
Programming Homework Help
 
PPTX
C Homework Help
Programming Homework Help
 
PPTX
Algorithm Assignment Help
Programming Homework Help
 
PPTX
Algorithm Homework Help
Programming Homework Help
 
Data Structures and Algorithm: Sample Problems with Solution
Programming Homework Help
 
Seasonal Decomposition of Time Series Data
Programming Homework Help
 
Solving Haskell Assignment: Engaging Challenges and Solutions for University ...
Programming Homework Help
 
Exploring Control Flow: Harnessing While Loops in Python
Programming Homework Help
 
Java Assignment Sample: Building Software with Objects, Graphics, Containers,...
Programming Homework Help
 
C Assignment Help
Programming Homework Help
 
Python Question - Python Assignment Help
Programming Homework Help
 
Best Algorithms Assignment Help
Programming Homework Help
 
Design and Analysis of Algorithms Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Programming Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
Programming Homework Help
 
Algorithm Homework Help
Programming Homework Help
 
Algorithms Design Assignment Help
Programming Homework Help
 
Algorithms Design Homework Help
Programming Homework Help
 
Algorithm Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Programming Homework Help
 
C Homework Help
Programming Homework Help
 
C Homework Help
Programming Homework Help
 
Algorithm Assignment Help
Programming Homework Help
 
Algorithm Homework Help
Programming Homework Help
 
Ad

Recently uploaded (20)

PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PPTX
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPT on the Development of Education in the Victorian England
Beena E S
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 

Computational Assignment Help

  • 1. For any help regarding Computational Methods Of Scientific Programming Assignment Help Visit : https://www.programminghomeworkhelp.com/, Email : [email protected] or call us at - +1 678 648 4277 programminghomeworkhelp.com
  • 2. Question (1): (a) Write Mathematica NoteBook which generates a table of error function (erf) and its derivatives for real arguments (z) between -‐3and 3 in steps of 0.25. The error function is defined by the equation below (but is rarely evaluated by performing the integration). (see http://mathworld.wolfram.com/Erf.html for information the error function ) 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 NoteBook and give an example of the output. (b) How would you change this NoteBook if 10 significant digits were required? Mathematica NoteBook should also be supplied Question (2): Write a NoteBook 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 NoteBook should not be specific to the lengths of your name (ie., the NoteBook should work with anyone’s name. As an example. An input of thomas abram herring would generate: Herring, Thomas A. Question (3): Write a Mathematica NoteBook 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 H(x)  Sx  Asin(2 x / )  Bcos(2 x / ) 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: Wind Drag Rolling Drag Fd 1/2ArCd V2 Fr  MrgCr programminghomeworkhelp.com
  • 3. 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 Rider force Fr  Pr /V 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). Your NoteBook 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 NoteBook can assume a constant power scenario and constant force at low velocities. As a test of your NoteBook use the following constants to compute: (a)Time to travel and energy used to travel 10 km along a path specified by S=0.01, 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 NoteBook which plots the velocity of the bike as a function of time and position along the path. programminghomeworkhelp.com
  • 4. Assume the following values Cd = 0.9 Cr = 0.007 Ar = 0.67 m2 r = 1.226 km/m3 g = 9.8 m/s2 Mr = 80 kg In this case, the Mathematica NoteBook will not be of the type used for fortran and C/C++. Look at the documentation on NDSolve for this problem. Your answer to this question should include: (a)The algorithms used and the design of your NoteBook (b)The Mathematica NoteBook with your code and solution (I run your NoteBook). (c)The results from the test case above. programminghomeworkhelp.com
  • 5. This latest version of Mathematica has some issues with copying and pasting equations and graphics from Microsoft Word. It also seems not to be able to reproduce subscripts and superscripts from word, which previously was able to do. It is not clear if the incompatibility is from the Microsoft Word or the Mathematica side. This is another indication of how changes in versions of software can have unintended consequences. (Question 1): (a) Write Mathematica NoteBook 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). (see http://mathworld.wolfram.com/Erf.html for information the error function ) 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 NoteBook and give an example of the output. (b) How would you change this NoteBook if 10 significant digits were required? Mathematica NoteBook should also be supplied ● Solution: Given that the error function is defined in Mathematica themost tricky part of the this problem is formarting the ourput. There are many ways to approach the output problem. programminghomeworkhelp.com
  • 6. Off@General::spell1D; H* Stops message about head looking like a command*L head = 8"Argument", "Erf@zD", "dErf@zDêdz"<; derf@arg_D := 2 ê Sqrt@PiD * Exp@-x^2D; ents = Table@8N@SetAccuracy@x, 10D, 3D, In[1]:= N@SetAccuracy@Erf@xD, 10D, 6D, N@SetAccuracy@derf@xD, 6D, 6D<, 8x, -3, 3, 0.25<D; full = Insert@ents, head, 1D; Out[6]//TableForm= TableForm@full, TableAlignments Ø RightD Argument Erf@zD dErf@zDêdz -3.00 -0.999978 0.00014 -2.75 -0.999899 0.00059 -2.50 -0.999593 0.00218 -2.25 -0.998537 0.00714 -2.00 -0.995322 0.02067 -1.75 -0.986672 0.05277 -1.50 -0.966105 0.118930 -1.25 -0.922900 0.23652 -1.00 -0.842701 0.41511 -0.750 -0.711156 0.64293 -0.500 -0.520500 0.87878 -0.250 -0.276326 1.06001 0.µ 10-10 0.µ 10-10 1.12838 0.250 0.276326 1.06001 0.500 0.520500 0.87878 0.750 0.711156 0.64293 1.00 0.842701 0.41511 1.25 0.922900 0.23652 1.50 0.966105 0.118930 1.75 0.986672 0.05277 2.00 0.995322 0.02067 2.25 0.998537 0.00714 2.50 0.999593 0.00218 2.75 0.999899 0.00059 3.00 0.999978 0.00014 (b) Output of table to 10 deciminal places. programminghomeworkhelp.com
  • 7. Off@ General::spell1D ; H * Stops message about head looking like a command*L head =8"Argument", "Erf@ zD ", "dErf@ zD êdz"<; In[22]:= derf@ arg_D := 2 êSqrt@ PiD* Exp@ -x^2D ; ents =Table@ 8 N@ SetAccuracy@ x, 10D , 3D , N@ SetAccuracy@ Erf@ xD , 10D , 10D , Out[26]//TableForm= N@SetAccuracy@derf@xD, 10D, 10D<, 8x, -3, 3, 0.25<D; full =Insert@ ents, head, 1D ; TableForm@full, TableAlignments Ø RightD Argument Erf@zD dErf@zDêdz -3.00 -0.999977910 0.000139253 -2.75 -0.999899378 0.0005862772 -2.50 -0.999593048 0.002178284 -2.25 -0.998537283 0.0071423190 -2.00 -0.995322265 0.0206669854 -1.75 -0.986671671 0.0527749959 -1.50 -0.9661051465 0.1189302892 -1.25 -0.9229001283 0.2365211224 -1.00 -0.8427007929 0.415107497 -0.750 -0.7111556337 0.642931069 -0.500 -0.5204998778 0.878782579 -0.250 -0.2763263902 1.060014129 0.µ 10-10 0.µ 10-10 1.128379167 0.250 0.2763263902 1.060014129 0.500 0.5204998778 0.878782579 0.750 0.7111556337 0.642931069 1.00 0.8427007929 0.415107497 1.25 0.9229001283 0.2365211224 1.50 0.9661051465 0.1189302892 1.75 0.986671671 0.0527749959 2.00 0.995322265 0.0206669854 2.25 0.998537283 0.0071423190 2.50 0.999593048 0.002178284 2.75 0.999899378 0.0005862772 3.00 0.999977910 0.000139253 programminghomeworkhelp.com
  • 8. period after the middle initial. If the names start with lower case letters, then these should be capitalized. The NoteBook should not be specific to the lengths of your name (ie., the NoteBook should work with anyone’s name. As an example. An input of thomas abram herring would generate: Herring, Thomas A. ● This problem is not too bad to solve. This solution works in >5.0 Mathematica and does explicitly some things such as splitting a string apart that are now Mathemat- ica commands (StringSplit). programminghomeworkhelp.com
  • 9. In[27]:= H * Define a function that will convert chararacter of a string to upper case *L confirst@a_D := StringReplacePart@a, ToUpperCase@StringTake@a, 81<DD,81, 1<D; H * Get the name from the user*L inname =InputString@"Enter Name Hfirst, middle, lastL "D; H * Convert whole string to lower case*L fullname = ToLowerCase@innameD; H * Now get the list of blanks in the string*L posblanks = StringPosition@fullname, " "D; H * Get the position of first blank*L posfirst = Extract@ Extract@ posblanks, 1D , 1D ; firstname = StringTake@ fullname, posfirst- 1D ; firstname = confirst@ firstnameD ; H * Use our confirst routine *L H * Get Middle Name *L posmid = Extract@ Extract@ posblanks, 2D , 1D ; midinit = StringTake@fullname, 8posfirst+1, posfirst +1<D;midinit = confirst@midinitD; H * Get Last Name *L lastname = StringTake@fullname, 8posmid+1, StringLength@fullnameD<D; lastname = confirst@lastnameD; H * Output the string *L finalname = lastname <> ", " <> firstname <> " " <> midinit <> "."; outline = "Input name " <> inname <> " converted to: " <> finalname; H * Output the results*L Print@outlineD; Input name thomas abram herring converted to: Herring, Thomas A. Write a Mathematica NoteBook 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 H(x)  Sx  Asin(2x /)  B cos(2x / ) programminghomeworkhelp.com
  • 10. 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: Wind Drag Rolling Drag Fd 1/2ArCdV 2 Fr  MrgCr 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 Rider force Fr  Pr /V 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). Your NoteBook 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 NoteBook can assume a constant power scenario and constant force at low velocities. As a test of your NoteBook 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 programminghomeworkhelp.com
  • 11. and a maximum force available of 20N. (b) (c) The position and velocity of the bike tabulated at a 100-‐second interval. Add graphics to your NoteBook 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 Ar = 0.67 m2  = 1.226 kg/m3 g = 9.8 m/s2 Mr = 80 kg In this case, the Mathematica NoteBook will not be of the type used for fortran and C/C++. Look at the documentation on NDSolve for this problem. Your answer to this question should include: (a) The algorithms used and the design of your NoteBook (b)The Mathematica NoteBook with your code and solution (I run your NoteBook). (c) The results from the test case above. ● There are several ways of approaching this problem and two solution are presented below. The problem itself is dvided into a number of cells that allow parts of prob- lem to be re-execuated. There two basic steps to the solution: (1)Use NDSolve to solve the second order differential equation that describes the problem. The solution effectively becomes an equation that returns values at any specified time. programminghomeworkhelp.com
  • 12. (2) Use FindRoot to determine when the bike has reached the end of track. cr = 0.007; area mass ● Set up the defaults first. This cell should be evaluated Clear@t, x, xd, hx, vx, xp, xd, th, daccD; cd = 0.90 ; H*Print@"Parameter cd ",cdD*L = 0.67; H* m^2 *L = 80; H* kg *L prider = 100; H* Power Watts*L fmax = 20; slope = 0.001; as = 5.0; bs = 0.0; lambda = 2000; tracklen = 10 000; outint = 100.0; H* Define the acceleration functions we will need*L grav = 9.8 ; rhoair = 1.226; Print@"Default Values set"D Default Values set ● Now allow the user to enter values of there own. This cell does not need to be evaluated if the default values are desired. programminghomeworkhelp.com
  • 13. In[82]:= Input@"Drag Coefficient ", cdD; Input@"Rolling friction coefficient ", crD; tracklen = Input@"Length of track HkmL ", tracklen ê 1000D * 1000.0; slope = Input@"Track slope ", slopeD; as = Input@"Sin Amplitude HmL ", asD; bs = Input@"Cos Ampliude Hm L", bsD; lambda = Input@"Periodic wavelength HkmL ", lambda ê 1000D * 1000.0; mass = Input@"Rider+Bike Mass HkgL ", massD; area = Input@"Rider Area Hm^2L ", areaD; cd = cr = outint = Input@"Output interval HsL", outintD; o Now set up the force model equations In[92]:= theta@xp_D := ArcTan@slope + as * Cos@2 * Pi * xp ê lambdaD * 2 * Pi ê lambda - bs * Sin@2 * Pi * xp ê lambdaD * 2 * Pi ê lambdaD htrack@xp_D := slope * xp + as * Sin@2 * Pi * xp ê lambdaD + bs * Cos@2 * Pi * xp ê lambdaD; H* Second derivative of surface for computing cenripical acceleration *L dy2dx2@xp_D := - as * Sin@2 * Pi * xp ê lambdaD * H2 * Pi ê lambdaL^2 - bs * Cos@2 * Pi * xp ê lambdaD * H2 * Pi ê lambdaL^2; vmag@xd_, zd_D := Sqrt@xd^2 + zd^2D; programminghomeworkhelp.com
  • 14. programminghomeworkhelp.com H* Acceleration due to drag *L - rhoair * vmag@xd, zdD * area * cd * - rhoair * vmag@xd, zdD * area * cd * dragx@xd_, zd_D := xd ê H2 * massL; dragz@xd_, zd_D := zd ê H2 * massL; H* Rolling rollx@xp_D rollz@xp_D H* Gravity gravx@xp_D gravz@xp_D force. This act along surface *L := - grav * cr * Cos@theta@xpDD; := - grav * cr * Sin@theta@xpDD; force acting perpendicular to surface *L := -grav * Cos@theta@xpDD * Sin@theta@xpDD; := +grav * Cos@theta@xpDD^2; H* Centripetal acceleration *L H* Could divide by Sqrt@H1+Tan@theta@xpDD^2L^3DD factor to curvature term. This change does not seem to make solution closer to track shape*L
  • 15. centx@xp_,xd_,zd_D := Hxd^2+ zd^2L* Sin@theta@xpDD* dy2dx2@xpD; centz@xp_,xd_,zd_D := Hxd^2+ zd^2L* Cos@theta@xpDD* dy2dx2@xpD; H* This commented code has expression for radius of curvature centx@xp_,xd_,zd_D := Hxd^2+zd^2L*Sin@theta@xpDD* dy2dx2@xpDêSqrt@H1+Tan@theta@xpDD^2L^3D; centz@xp_,xd_,zd_D := Hxd^2+zd^2L*Cos@theta@xpDD* dy2dx2@xpDêSqrt@H1+Tan@theta@xpDD^2L^3D; *L H* To see the effects of the centripetal force, remove the comments below centx@xp_,xd_,zd_D :=0; centz@xp_,xd_,zd_D :=0; *L H* Now the rider force *L ridrx@xp_,xd_,zd_D := HMin@If@vmag@xd,zdD> 0, priderêvmag@xd,zdD,fmaxD, fmaxDêmassL* Cos@theta@xpDD; ridrz@xp_,xd_,zd_D := HMin@If@vmag@xd,zdD> 0, priderêvmag@xd,zdD,fmaxD, fmaxDêmassL* Sin@theta@xpDD; Print@AccelerationfunctionsSetD AccelerationfunctionsSet ● The following cell can be used to test that the acceleration functions above gener- ate numeric results when called with distance and velocity. This test is useful if NDSolve does not return answer. programminghomeworkhelp.com
  • 16. In[121]:= dx = 1500.; txv = 2.0; tzv = 0.01; Print@"Slope ", theta@dxD, " 2nd derivative ", dy2dx2@dxD, " Height ", htrack@dxDD Print@"Drag X ", dragx@txv, tzvD, " Z ", dragz@txv, tzvDD Print@"Roll X ", rollx@dxD, " Z ", rollz@dxDD Print@"Gravity X ", gravx@dxD, " Z ", gravz@dxDD Print@"Centripetal X ", centx@dx, txv, tzvD, " Z ", centz@dx, txv, tzvDD Print@"Rider X ", ridrx@dx, txv, tzvD, " Z ", ridrz@dx, txv, tzvDD Slope 0.001 2nd derivative 0.000049348 Height -3.5 Drag X -0.0184822 Z -0.0000924109 Roll X -0.0686 Z - 0.0000686 Gravity X -0.00979999 Z 9.79999 Centripetal X 1.97397 µ 10- 7 Z 0.000197397 Rider X 0.25 Z 0.00025 ● Now set up the solution for NDSolve. There are two equations in the x and z accel- erations and initial conditions for x and z and x' and z' at time zero. The solution is set to solve for a maximum of 10000 seconds. This is OK for the standard case but may need to be modified for other longer running cases. The evaluaton of the solution is saved for x and z positions and z and z velocities. (NDSolve contains examples of setting up these solutions. We can then find the length of the time need by solving the equation xp[t]-tracklen == 0. This is not with FindRoot. programminghomeworkhelp.com
  • 17. In[177]:= solution = NDSolve@ 8x''@tDã ridrx@x@tD,x'@tD,z'@tDD+ dragx@x'@tD,z'@tDD+ rollx@x@tDD+ gravx@x@tDD+ centx@x@tD,x'@tD,z'@tDD, z''@tDã ridrz@x@tD,x'@tD,z'@tDD+ dragz@x'@tD,z'@tDD+ rollz@x@tDD+ gravz@x@tDD- grav+ centz@x@tD,x'@tD,z'@tDD, x@0D== 0,z@0Dã 0, x'@0Dã 0,z'@0Dã 0<,8x,z<,8t,0,10000<D; xp@t_D := First@Evaluate@x@tD ê. solutionDD; zp@t_D:= First@Evaluate@z@tDê.solutionDD; xv@t_D:= First@Evaluate@x'@tDê.solutionDD; zv@t_D:= First@Evaluate@z'@tDê. solutionDD; H* Compute the error in the distance *L endt = t ê. FindRoot@xp@tD- tracklenã 0,8t,1,3000.0<D; H* Now integrate to get work done *L work = NIntegrate@mass* Sqrt@xv@tD^2+ zv@tD^2D* Sqrt@ridrx@xp@tD,xv@tD,zv@tDD^2+ ridrz@xp@tD,xv@tD,zv@tDD^2D,8t,0,endt<, AccuracyGoalØ 4D; Print@"Time to reach end of track ",endt," sec, Speed ", xv@endtD," mês"D; Print@"Work done ",work," Joules, ",workê4.1868ê10^3, " kcal"D; NIntegrate::ncvb : NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t near 8t<= 8678.279<. NIntegrate obtained 174398.48726962117` and 0.39321119853291564` for the integral and error estimates. à Time to reach end of track 2255.17 sec, Speed 2.65009 mês Work done 174398. Joules, 41.6544 kcal ● The case above gives an example of how tricky Mathematica can be in telling you what it is actually doing. In the integration above for work a numerical rounding error message is printed. The message suggests there is some problem around 678 seconds. The cell below divides the calculation into 2 parts normally split at around 678 seconds and in this case no numerical error warning is printed. It’s not at all clear why the program is behaving this way. programminghomeworkhelp.com
  • 18. In[166]:= tt = 678.279; worksplit = NIntegrate@mass * Sqrt@xv@tD^2 + zv@tD^2D * Sqrt@ridrx@xp@tD, xv@tD, zv@tDD^2 + ridrz@xp@tD, xv@tD, zv@tDD^2D, 8t, 0, tt<D + NIntegrate@mass * Sqrt@xv@tD^2 + zv@tD^2D * Sqrt@ridrx@xp@tD, xv@tD, zv@tDD^2 + ridrz@xp@tD, xv@tD, zv@tDD^2D, 8t, tt, endt<D; Print@"Work computed in one step ", work, " and split at time ", tt, " " , worksplit, ". Difference in results ", work - worksplitD; Work computed in one step 174 399. and split at time 678.279 174 399.. Difference in results 0. ●Final output for version A (full solutions) In[185]:= Print@"12.010 HW 4: Mathematica Bike Problem"D; Print@"Solution Parameters"D; Print@"Track Length ", tracklen ê 1000.0, " km"D; Print@"Track Slope ", slope, " Sin Cos ", as, " ", bs, " m, Lambda ", lambda ê 1000., " km"D; Print@"Rider Power ", prider, " Watts, Max Force ", fmax, " N"D; Print@"Time to reach end of track ", endt, " sec, Speed ", xv@endtD, " mês"D Print@"Work done by rider ", work, " Joules, ", work ê 4.1868 ê 10^3, " kcal" D programminghomeworkhelp.com
  • 19. 12.010 HW 4: Mathematica Bike Problem Solution Parameters Track Length 10. km Track Slope 0.001 Sin Cos 5. 0. m, Lambda 2. km Rider Power 100 Watts, Max Force 20 N Time to reach end of track 2255.17 sec, Speed 2.65009 mês Work done by rider 174 398. Joules, 41.6544 kcal programminghomeworkhelp.com
  • 20. ● Add some graphics to the results: Velocity versus time, Z position versus X posi- tion, and difference from track shape. The latter plot shows how well our integra- tion matched the actual shape of the track. In[241]:= Plot@ xv@tD, 8t, 0, endt<, AxesLabel Ø 8"Time HsecL", "Velocity HmêsL"<D ParametricPlot@ 8xp@tD ê 1000 , zp@tD<, 8t, 0, endt<, AxesLabel Ø 8"X position HkmL", "Z positionHmL"<, AspectRatio Ø 1 ê 1D ParametricPlot@ 8xp@tD ê 1000 , Hzp@tD - htrack@xp@tDDL * 1000.<, 8t, 0, endt<, AxesLabel Ø 8"X position HkmL", "Error in Z HmmL"<, AspectRatio Ø 1 ê 1D Out[241]= 500 1000 1500 2000 Time 3 2 1 4 Velocity HmêsL 7 6 5 programminghomeworkhelp.com
  • 21. Out[242]= 2 4 6 8 10 X position 5 10 Z positionHmL programminghomeworkhelp.com
  • 22. 2 4 6 8 10 X position - 0.4 - 0.3 - 0.1 Out[243]= - 0.2 0.1 Error in Z HmmL 0.2 -0.5 ● We now use table and table form to have to put the positions and velocities as a function of the interval selected by the user. (The default interval is 100 seconds). To generate the table with 100s output, and to add the final value, we generate the table in two parts and save the table in a list called outlst. We use the append function to join the two tables together. programminghomeworkhelp.com
  • 23. In[274]:= outlst = Table@8t, xp@tD, zp@tD, xv@tD, zv@tD<, 8t, 0, endt, outint<D; H* Now add the final entry to the tabe; *L outlst = Append@outlst, Transpose@Table@8t, xp@tD, zp@tD, xv@tD, zv@tD<, 8t, endt, endt, outint<DDD; TableForm@outlst, TableHeadings Ø 8None, 8"Time HsL", "X Pos HmL", "Z pos HmL", "X Vel HmêsL", "Z Vel HmêsL"<<D Out[276]//TableForm= Time HsL 0 X Pos HmL 0. Z pos HmL 0. X Vel HmêsL 0. Z Vel HmêsL -5.29396µ 10-23 100 79.9901 1.32329 1.48869 0.0241386 200 306.763 4.41341 3.36696 0.0335387 300 826.797 3.41531 6.79761 -0.0845564 400 1513.81 -3.48135 5.87698 0.00988077 500 1951.68 1.19559 2.95947 0.0489105 600 2202.42 5.17194 2.65422 0.0361969 700 2608.52 7.32075 5.8297 -0.0247871 800 3292.9 -0.685554 6.88819 -0.0586485 900 3834.83 1.35511 3.88251 0.0568391 1000 4117.37 5.91931 2.35353 0.0368374 1100 4428.12 9.30101 4.53331 0.0204786 1200 5046.56 4.31778 7.24973 -0.105412 1300 5681.7 1.47426 4.97372 0.0471862 1400 6035.25 6.58758 2.48085 0.0412101 1500 6294.17 10.2845 3.32052 0.0347469 1600 6803.7 9.69517 6.71443 -0.0793262 1700 7493.54 2.49435 5.98646 0.00407604 1800 7941.44 7.0264 3.03341 0.0498764 1900 8193.43 11.0479 2.60451 0.0361917 2000 8588.77 13.3952 5.72489 -0.0190286 2100 9269.22 5.52648 6.96317 -0.0655712 2200 9821.37 7.16001 3.99206 0.0570797 2255.17 10000. 9.99951 2.65009 0.0442763 programminghomeworkhelp.com
  • 24. tance along the sirface. These could be derived given that we have the eqautions. A simpler solution to solve for the horizontal motion and compute the z-motion consistent wth staying on the track. The z-motion is needed because drag and rider force depend on the total velocity not just the horizontal velocity. We use the same constants above but we re-define the accerations and NDSolve here. In[284]:= theta@xp_D := ArcTan@slope + as * Cos@2 * Pi * xp ê lambdaD * 2 * Pi ê lambda - bs * Sin@2 * Pi * xp ê lambdaD * 2 * Pi ê lambdaD H* Get total velocity given running on track *L vtot@xd_, xp_D := Sqrt@xd^2 + Hxd * Tan@theta@xpDDL^2D; dacc@xd_, xp_D := -cd * rhoair * vtot@xd, xpD^2 * area ê H2 * massL; racc@th_D := - grav * cr * Cos@thD; facc@xd_, xp_D := Min@If@ vtot@xd, xpD > 0, prider ê vtot@xd, xpD, fmaxD, fmaxD ê mass gacc@th_D := - grav * Sin@thD; Print@"1-D accelerations set"D 1-D accelerations set programminghomeworkhelp.com ● Alternative solution, Here we solve the one dimensional problem which is basi- cally the roller coaster solution that keeps the bike on the ground. In the Fortran and C-versions we computed the forces along the sloped surface and integrated horizontal motions from the motion along the slope. If a similar approach is fol- lowed here, then we need expressions for height and slope as functions of the dis-
  • 25. H* Set up differential equations to be be solved, x@tD is horizontal position, There is still a problem here with along track versus horizontal distance Here we use y for the dependent variable*L solnb = NDSolve@ 8y''@tD ã Hdacc@y'@tD, y@tDD + gacc@theta@y@tDDD + racc@theta@y@tDDD + facc@y'@tD, y@tDDL * Cos@theta@y@tDDD, y@0D ã 0, y'@0D ã 0.0<, y, 8t, 0.0, 10 000.0<, AccuracyGoal Ø 10D; py@t_D := Evaluate@y@tD ê. solnbD; vy@t_D := Evaluate@y'@tD ê. solnbD; H* Compute the error in the distance *L endb = t ê. FindRoot@py@tD - tracklen ã 0 , 8t, 1, 3000.0<D; work = NIntegrate@mass * facc@First@vy@tDD, First@py@tDDD * vtot@First@vy@tDD, First@py@tDDD, 8t, 0, endt<D; Print@"Time to reach end of track ", endb, " sec, Speed ", First@vy@endtDD, " mês"D; Print@"Work done ", work, " Joules, ", work ê 4.1868 ê 10^3, " kcal" D; Time to reach end of track 2255.05 sec, Speed 2.64848 mês Work done 174 405. Joules, 41.6558 kcal Plot@8vy@tD, Sqrt@xv@tD^2 + zv@tD^2D<, 8t, 0, endb<, PlotRange Ø All, AxesLabel Ø 8"Time HsecL", "Velocity HmêsL"<D Plot@Hvy@tD - Sqrt@xv@tD^2 + zv@tD^2DL * 1000, 8t, 0, endb<, PlotRange Ø All, AxesLabel Ø 8"Time HsecL", "Diff Vel HmmêsL"<D In[311]:= programminghomeworkhelp.com
  • 26. Out[311]= 500 1000 1500 2000 3 2 1 4 Velocity HmêsL 7 6 5 Out[312]= 500 1000 1500 2000 Time - 4 - 2 2 4 Diff Vel HmmêsL 6 ● Now output table of values programminghomeworkhelp.com
  • 27. In[308]:= outl1d = Table@8t, py@tD, vy@tD<, 8t, 0, endb, outint<D; H* Now add the final entry to the tabe; *L outl1d = Append@outl1d, Transpose@Table@8t, py@tD, vy@tD<, 8t, endb, endb, outint<DDD; TableForm@outl1d, TableHeadings Ø 8None, 8"Time HsL", "X Pos HmL", "X Vel HmêsL"<<D Out[310]//TableForm= Time HsL X Pos HmL X Vel HmêsL 0 0. 0. 100 80.0296 1.48938 200 306.907 3.36857 300 827.102 6.79856 400 1514.08 5.87554 500 1951.82 2.95863 600 2202.58 2.65548 700 2608.89 5.83165 800 3293.34 6.88692 900 3835.08 3.8804 1000 4117.54 2.35409 1100 4428.5 4.537 1200 5047.16 7.25006 1300 5682.12 4.97145 1400 6035.47 2.48028 1500 6294.5 3.32362 1600 6804.39 6.7169 1700 7494.16 5.98318 1800 7941.75 3.03121 1900 8193.74 2.6065 2000 8589.47 5.72868 2100 9270.08 6.96082 2200 9821.86 3.98801 2255.05 10000. 2.65031 programminghomeworkhelp.com