Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % AE 5139 Intro to CFD
- % Homework 1
- % Due: 27 Aug 2019
- % Christopher Bates
- % Pastebin Link:
- clear all
- close all
- clc
- dx = [0.1, 0.01];
- x0 = 0;
- xmax = 3;
- syms x
- dydx = @(x) x^2 + tanh(x);
- y = @(x) (1/3)*x^3 + log(cosh(x));
- Error = zeros(2);
- i = 0;
- for k = dx
- i = i+1;
- X = x0:dx(i):xmax;
- [numRows, numElems] = size(X);
- y_apx = zeros(numElems);
- y_apx(1) = 0 + dydx(X(1)) * dx(i);
- for j = 2:numElems
- y_apx(j) = y_apx(j-1) + dydx(X(j-1)) * dx(i);
- if j == numElems
- figure
- plot(X,y_apx)
- xlabel('x-axis','Interpreter','latex')
- ylabel('y-axis','Interpreter','latex')
- mytitleText = ['Approximate value of integral for \Deltax = ',num2str(dx(i))];
- title(mytitleText,'Interpreter','tex' );
- Error(i) = (y(xmax) - y_apx(numElems)) / y(xmax);
- end
- end
- if i == 1
- ValueTable = table(X',y_apx);
- ValueTable.Properties.VariableNames = {'x','y'};
- writetable(ValueTable,'ValueTable.txt')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement