- Parent Category: Programming Assignments' Solutions
We Helped With This MATLAB Programming Assignment: Have A Similar One?
|More Info||Online Matlab Tutor|
Short Assignment Requirements
% Name Brad Turner % Date 11/16/2017 % Section #204 % In-Lab 10 clear all; close all; clc % clear functions %% Instructor-Guided Portion %% Problem 1 - Snow Plotting % Import the data file and predict the snow accumulation. % Load snowd.dat imported from Moodle: snowd = load('snowd.dat') % a. Fit a quadratic curve to the data: weeks = 1:length(snowd); poly = polyfit(weeks, snowd, 2); % b. Predict when the snow will completely disappear: snowGone = max(roots(poly)); % c. Co-plot the snow data and the quadratic curve: % Plot the snow data: plot(weeks, snowd, 'wo'); % Plot the quadratic curve: x = linspace(1,ceil(snowGone),100); y = polyval(poly,x); hold on; plot(x,y); % Set plot properties: set(gca, 'Color', 'k'); ylim([0,max(snowd)]); xlabel('Week #'); ylabel('Snow Depth (in)'); title( sprintf('Snow Gone by Week %d', ceil(snowGone))); %% Problem 2 - Enthalpy % Solve for the change in enthalpy of oxygen. a = 25.48; b = 1.523e-2; c = -.715e-5; d = 1.312e-9; % Set variable T as symbolic: syms T % Assign variable constants given in problem: equation = a + b * T + c * T^2 +d *T^3 % Use the given integral to find change in enthalpy: val = double(int(equation,300,1000)) %% Problem 3 - Quadratic Formula % Create a symbolic expression for the quadratic equation and solve. clear all % Create symbolized variables: syms x a b c; % Write equation using symbolized variables: quadratic = a*x^2+b*x+c; % Solve using the quadratic equation and display: newQuad = solve(quadratic,x); pretty(newQuad); % Substitute given constants into equation and solve using subs(): newQuad = subs(newQuad,a,1/21); newQuad = subs(newQuad,b,46); newQuad = subs(newQuad,c,-2016); pretty(newQuad); r =double(newQuad); %% Problem 4 - Matrix Math % Write the system of equations as matrices and solve for x, y, and z.A A = [2 7 1; 2 0 3; 4 1 3]; % Re-write as matrices (AX=B): B = [ 2 ; 1 ; 3 ]; % a. Find the inverse and determinant of A: invA = inv(A); detA = det(A); % b. Solve for unknowns using left divide (AB): X1 = A B; % c. Solve for unknowns using inverse matrix multiplcation (A-1*B): X2 = invA * B %% Independent Portion
In-Lab 10: Symbolic Math, Matrix Math
For this assignment, you will create an m-file as your main script. The file must have the following naming convention: “FirstName_LastName_InLab10.m”. Make sure to do the following for full credit:
▪ Create separate cells for each problem ▪ Suppress all unnecessary output
▪ Comment your code thoroughly ▪ Store all answers as variables
To submit multiple files at once, zip them all together in MATLAB and rename using the above convention. Add the following header to every file you submit:
% Section #
% Assignment (i.e. In-Lab 1)
Instructor-Guided Portion (download InLab10.m from the Moodle page)
1. The depth of snow in inches has been measured in a very cold location every week since snow started accumulating. After 15 weeks, the snow is melting and starting to recede, but it’s all gone just yet. Load the recorded depths stored in the file snowd.dat on Moodle into MATLAB.
a. Predict the depth of snow by fitting a quadratic curve to the actual data points.
b. Determine the week when the snow will be completely gone (rounded up).
c. Plot the actual depth data and the quadratic curve fit from week 0 to the last week.
i. Include the final week in the plot title
ii. The x-axis should range from 0 to the final week value
iii. The y-axis should range from 0 to the maximum recorded depth of snow iv. Match all labels, line/point styles, and colors as shown in the sample figure below
2. The change in enthalpy ∆ℎ can be defined as the integral of the heat capacity from an initial temperature 𝑇1 to a final temperature 𝑇2. This can be written as follows:
∆ℎ = ∫ 𝑎 + 𝑏𝑇 + 𝑐𝑇2 + 𝑑𝑇3𝑑𝑇
Find the change in enthalpy of oxygen for a temperature range of 300 to 1,000 K. The values of constants a, b, c, and d are given:
𝑎 = 25.48
𝑏 = 1.523 𝑥10−2
𝑐 = −0.716 𝑥10−5
𝑑 = 1.312 𝑥10−9
3. Create a symbolic representation of a quadratic equation, 𝑎𝑥2 + 𝑏𝑥 + 𝑐, then use solve() with respect to 𝑥 to create the quadratic formula. View the formula using pretty(). Finally, use subs() to find the value of 𝑥 if 𝑎 = 1⁄21, 𝑏 = 46, and 𝑐 = −2016.
4. Re-write the following system of equations in matrix form (AB = X) and perform the operations.
2𝑥 + 7𝑦 + 𝑧 = 2
2𝑥 + 3𝑧 = 1
4𝑥 + 𝑦 + 3𝑧 = 3
a. Find the inverse and determinant of A
b. Solve for x, y, and z using left divide
c. Solve for x, y, and z using inverse matrix multiplication
Independent Portion: Cody Problems for Lab 10
For this section, you will solve problems provided on the Cody Coursework website:
It is recommended to solve the problems in MATLAB, then test your solution with Cody Coursework. To get credit for a problem, your solution must pass all tests. Copy your Cody scripts into your In-Lab m-file for future reference.