• API
• FAQ
• Tools
• Archive
SHARE
TWEET # AE5139HW1 a guest Aug 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % AE 5139 Intro to CFD
2. % Homework 1
3. % Due: 27 Aug 2019
4. % Christopher Bates
5. % Pastebin Link:
6.
7. clear all
8. close all
9. clc
10.
11. dx           = [0.1, 0.01];
12. x0           = 0;
13. xmax         = 3;
14.
15. syms x
16. dydx         = @(x) x^2 + tanh(x);
17. y            = @(x) (1/3)*x^3 + log(cosh(x));
18.
19.
20. Error = zeros(2);
21.
22. i = 0;
23.
24. for k = dx
25.     i = i+1;
26.
27.    X = x0:dx(i):xmax;
28.
29.    [numRows, numElems] = size(X);
30.
31.    y_apx = zeros(numElems);
32.
33.    y_apx(1) = 0 + dydx(X(1)) * dx(i);
34.
35.    for j = 2:numElems
36.
37.        y_apx(j) = y_apx(j-1) + dydx(X(j-1)) * dx(i);
38.
39.        if j == numElems
40.            figure
41.            plot(X,y_apx)
42.            xlabel('x-axis','Interpreter','latex')
43.            ylabel('y-axis','Interpreter','latex')
44.            mytitleText = ['Approximate value of integral for \Deltax = ',num2str(dx(i))];
45.            title(mytitleText,'Interpreter','tex' );
46.
47.            Error(i) = (y(xmax) - y_apx(numElems)) / y(xmax);
48.        end
49.    end
50.
51.    if i == 1
52.        ValueTable = table(X',y_apx);
53.        ValueTable.Properties.VariableNames = {'x','y'};
54.        writetable(ValueTable,'ValueTable.txt')
55.    end
56. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top