MATLAB编程辅导、MATLAB scrip语言辅导报告
- 首页 >> Matlab编程Name: Lab Time (ECampus write “ECampus”): MTWRF 0000
By writing or typing your name below you affirm that all of the work contained herein is your own, and was not copied or copied and altered.
Note: Failure to sign this page will result in a 50 point penalty. Failure to list people you worked with may result in no grade for this homework.
BEFORE YOU BEGIN
Please read “ENGR 112 Homework instructions.pdf” in the Canvas module “Start Here.”
Learning Objectives:
You should be able to answer the following questions:
What is a script file?
What is the difference between a script file and the command window?
How do you create variables?
How can you examine the values of variables?
How do you create equations, pass them variables, and print out the results?
How do you display the values of variables?
Homework Guidelines:
Write one script per problem. Name each script something you’ll remember (e.g. “prob1trigFunc.m”).
Start problems with pseudo code (comments with %).
Write an English description of the script/function at the top of the page.
Outline your steps as comments before writing actual code.
Write your MATLAB statement(s) under each pseudocode step.
Variables need units next to them as a comment.
Print results as fully formed sentences with fprintf().
Use the correct number of decimal places for numbers and include units (if any).
Copy all required components into spaces below problem.
Specific Coding Notes:
Use variables for constants in equations (where it makes sense).
Example: You have the equation “y = a + b – 2”. Given a = 2 and b = 4, find y.
☹ NO ☹😊 YES 😊
% Calculate y
y = 2 + 4 - 2;
% Declare variables FIRST
a = 2;
b = 4;
% Use those variables in the equation
y = a + b - 2;
Grading Checkpoints
CriteriaComponentNoYes
[30%] Comments and PseudocodeDeclared units on all variables?
English description of problem at top?
Comments outlining your steps?
[20%] Output formattingUsed fprintf() to make complete sentences (when required)?
Correct units on answers?
Correct number of decimal places?
[50%] FunctionalityScript computes correct value(s)?
Correctly converted units in script when needed?
Problem 1
Write a script to solve and output the answers to the following equations. All quantities have no units. Assume x = 45. Format output to 5 decimal places.
y=(〖5x〗^3 √(〖2x〗^2 ))/(cos(x+5)) , where x is in degrees
t=1/(sin(1/x)) , where x is radians
z=〖2e〗^(x/380)+x ln〖(x^2/3)〗
Self check: y = xxxxxxxx.xx5xx , t= x.xxx25 and z = x9x.4xxx1
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).
Problem 2
From elementary physics, we know that the distance a projectile travels (e.g. when fired from a cannon) depends on both the initial velocity v and the launch angle θ:
x(t)=v t cos(θ)
y(t)=v t sin(θ)〖-1/2〗 gt^2
where x(t) and y(t) are the distances traveled in x and y respectively after time t has passed (g is gravity, g = 9.8 meters/second2).
a) Given an initial velocity of 3.5 meters per second and an angle of 48 degrees above the ground, calculate the (x,y) location of the projectile at both time 0.45
seconds and 0.7 seconds.
Self-check: x(0.45) = x.x5xx m, y(0.7) = -x.x8xx m
b) Use your program to find the t value (approximately – within 0.1 meters) where the projectile hits the ground, assuming it was launched from ground height. Print
out both the t value and the position. Hint: The projectile goes up, then goes down… You do not need to write any new or special code to do this, just try different t
values and let MATLAB do the calculation.
Self-check: |y(t)| < 0.1 for your t value
Format all output to 4 decimal places.
A picture to help you visualize the equations:
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).
3. The Richter scale is a measure of the intensity of an earthquake. The magnitude M (unitless) of an earthquake as measured on the Richter scale is
M=2/3 log_10〖E/E_0 〗
where E0 = 104.4 Joules is a constant (energy of a small reference earthquake). Write a program that takes as input (from the user) the magnitude of two earthquakes
and outputs the energy difference between them. Check your answer using a magnitude 6.8 (Guatemala, 2017) and 9.0 (Japan, 2011) earthquake. Format your output in
scientific notation.
Self-check: Difference is x.x39xxxe+xx
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).
For the following see the Full Term assignments module in Canvas – the assignments and self-checks are both there. I’d suggest at least skimming through the entire
document to get an idea of what you’ll be doing in subsequent weeks.
4. Teacup problem 1 [Equations]
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).
5. Epidemic problem 1 [Equations]
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).
6. Euler leaf problem 1 [Equations]
Comments for grader/additional information (if any)
Script File
% Copy and paste your script here. Must be size 10, same as MATLAB font and color.
Command Window Output
Copy and paste the command window output here (same font, size 10).