project1_skeleton_1

m

School

University of Central Florida *

*We aren’t endorsed by this school

Course

3034C

Subject

Aerospace Engineering

Date

Oct 30, 2023

Type

m

Pages

3

Uploaded by MagistrateNeutronAlpaca26

Report
% NAME: % DATE: 09/08/23 % ASSN: PROJECT 1 % CSRN: EML 3034C Modeling Methods in MAE % Clear command window, close all graphs, clear workspace clc, close all, clear % ======================================================================== fprintf("============================================================\n") fprintf("Project 1 - Round-off vs Truncation Error\n") fprintf("\n") display(date()) fprintf("============================================================\n\n") % ======================================================================== format short e % Define the function f(x) f = @(x) 2.5-1.25.*cos(3.8.*x); % Insert Function f(x) df = @(x) 4.75.*sin(3.8.*x); % Insert Exact First Derivative df(x) % Select x value to evaluate derivative x = 5.25; % Double-Precision % loop through the exponents for each delta x value and evaluate the derivative for i = 1:20 % calculate the delta x del(i,1) = 10^(-i); % Backward Finite Difference backward(i,1) = (f(x)-f(x-del(i,1)))/del(i,1); % Forward Finite Difference forward(i,1) = (f(x+del(i,1))-f(x))/del(i,1); % Central Finite Difference central(i,1) = (f(x+del(i,1))-f(x-del(i,1)))/(2.*del(i,1)); % calculate the errors compared to exact (analytical) derivative backward_error(i,1) = abs(df(x)-backward(i,1)); forward_error(i,1) = abs(df(x)-forward(i,1)); central_error(i,1) = abs(df(x)-central(i,1)); end % Plot the error vs del x for each method on the log scale figure(1) hold on % Scale of log for axis set(gca, 'XScale', 'log', 'YScale', 'log') % the loglog() function is the same as plot() but on log scale for both axes loglog(del,backward_error) loglog(del,forward_error) loglog(del,central_error)
xlabel('\Delta'), ylabel('Error') title('Error on Forward, Backward, and Central') legend('Forward','Backward','Central') grid on, hold off % assemble the results into a table (actually a matrix) Table = [del forward_error backward_error central_error]; % print to screen fprintf("=========== Double Precision Results ===========\n") disp(Table) % Repeat everything, but in single precision % Select x value to evaluate derivative x = single(5.25); for i = single(1:20) % calculate the delta x del(i,1) = 10^(-i); % Backward Finite Difference backward(i,1) = (single(f(x))-single(f(x-del(i,1))))/single(del(i,1)); % Forward Finite Difference forward(i,1) = (single(f(x+del(i,1)))-single(f(x)))/single(del(i,1)); % Central Finite Difference central(i,1) = (single(f(x+del(i,1)))-single(f(x-del(i,1))))/ (2.*single(del(i,1))); % calculate the errors compared to exact (analytical) derivative backward_error(i,1) = abs(single(df(x))-backward(i,1)); forward_error(i,1) = abs(single(df(x))-forward(i,1)); central_error(i,1) = abs(single(df(x))-central(i,1)); end % Plot the error vs del x for each method on the log scale figure hold on % Scale of log for axis set(gca, 'XScale', 'log', 'YScale', 'log') % the loglog() function is the same as plot() but on log scale for both axes loglog(del,backward_error) loglog(del,forward_error) loglog(del,central_error) xlabel('\Delta'), ylabel('Error') title('Error on Forward, Backward, and Central') legend('Forward','Backward','Central') grid on % assemble the results into a table (actually a matrix) fprintf("\n\n\n\n\n")
Table = [del forward_error backward_error central_error]; % print to screen fprintf("=========== Single Precision Results ===========\n") disp(Table); fprintf("\n\n\n\n\n\n\n") %ADDED TO MAKE IT PRINT MORE LEGIBLY WHEN PUBLISHED AS PDF
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Find the gradient vector field (F(x, y, z)) of ƒ(x, y, z) = x²y^¹ z³ 2 F(x, y, z) = (
Q: (a) selecting a person who is Group O or type Rh P(Group O or Type Rh +) = (b) selecting a person…
Q: The Cardstock Manufacturing Division of the Pulp Paper Company reported the following results from…
Q: 2N2O5(aq) → 4NO2(aq) + O2(g) Which choice represents the relative rate expression between N2O5 and…
Q: 20 ft -200 ft- Exercise Figure 8.1 8.1). The concrete has a unit weight of 2.4 Mg/m³ (150 lb/ft3).…
Q: Let x be a random variable that represents the weights in kilograms (kg) of healthy adult female…
Q: Find an equation for the circle of curvature of the curve r(t) = (2 ln t)i - 3t + (1/t)4j, e-2…
Q: Find the curvature of the curve 7(t) = (4cos(4t), 4 sin(4t), 5t) at the point t = 0 Give your answer…
Q: Use the echelon method to solve the following system of two equations in two unknowns. Check your…
Q: Differentiate the function below y = ln ( ( etan x √(x2 +1) )  /  (x-3)5)
Q: From the following rocks prepare a list in order of their decreasing unconfined compressive…
Q: find the linearization L(x, y) of the function ateach point. ƒ(x, y) = 3x - 4y + 5 at a. (0, 0), b.…
Q: What is E cell for the following reaction? 2 Ag(s) + Sn²+ (aq) → 2 Ag*(aq) + Sn(s) Ag (aq) + e E =…
Q: Minimize g = 5y₁ + 3y2 subject to 3y1 + y2 ≥ 33 31+y2 > 27 y12y2 44 31 > 0, 2 > 0 If no solutions…
Q: What is used to indicate a weak relationship in an ERD in Crow’s Foot notation?     Dashed line…
Q: 85 kN 70 kN 2m|2m 4 m 45 KN 85 kN 2m|2m
Q: Write a net ionic equation for the reaction that occurs when calcium sulfite (s) and excess nitric…
Q: Find the inverse of A = 3 0 1 3 1 0 10 0 3
Q: The perimeter of a rectangular garden is 48 feet. The length of the garden is 2 feet more than the…
Q: All of the following reasons are explanations for why India never achieved the political…
Q: Find the value of integral 0 ≤ t ≤ 6. So (2² (x² + yz)ds, where C is parmeterized by r(t) = ( − 4t,…
Q: For this problem, carry at least four digits after the decimal in your calculations. Answers may…