Question
Note: Only either use MATLAB or JAVA to write codes in order to complete this assignment. The code and the output must answer all the question and follow all the instructions mentioned in the assignment. Please use good plotting techniques (and labeling) to plot any graphs. If you have any questions feel free to ask me by commenting.
For this assignment, you will need to write some short codes to complete the following problems. You are free to write m any language you prefer, including MATLAB. provided you do not use any built-in commands or intrinsic functions to shortcut the methods you are asked to investigate (though you may use them to verify your answers). For instance, you may not use MATLAB's f zero command to find the roots of an equation. The only restrictions on your codes are that they must write your output to a file, and numbers m vour results must be properly formatted with an appropriate number of significant figures. Use exponential notation where appropriate. Please turn in both hard and electronic copies of both your codes and your results. Your codes and results may be combined into a single file for electronic submission, provided that it is clear which results correspond to which code. Root finding has its place in several applications in the areas of vibration (modal analysis of wing flutter), acoustics (microphone and speaker placement for acoustic signature measurements), and computational fluid dynamics (matching governing equations to proper numerical schemes for aerodynamic calculations). Determine the highest real root, out to exactly three decimal points, of the polynomial f(x) = 1.5x2 - 8.lx2 + 18.6x - 10 a) graphically (no code required; simply plot you may use any function of any software to do this) b) using fixed-point iteration (five iterations, x.- = 1) c) using Xewton-Raphson (five iterations, x, = 1) d) using Secant method (five iterations, x1- = 01 x0 = 1) Compute the approximate percent relative errors out to exactly four decimal points for each iteration of your solutions as described in the notes. 2. There are many applications where numerical integration is required in aerospace engineering. Examples include integrating a pressure distribution about an airfoil to find lift and drag, integrating a time-dependent drag profile on a rocket to determine time of flight and burnout altitude, and integrating a probability distribution function to find the average fuel drop diameter in an aircraft engine. In many instances, the function to be integrated may be a set of discrete data points rather than being analytical, but the technique is similar. Integrate the following function both analytically and numerically: Use both the trapezoidal and Simpson's 13 rules to numerically integrate the function out to exactly seven decimal points. For both cases, start with n = 1, then double the number of segments until your last computation includes 512 segments. Compute the percent relative errors, out to exactly four decimal points, for the numerical results (as compared to the analytic answer). Numerical Answer - Analytic Answer/Analytic Answer
Explanation / Answer
clear all
close all
clc
x=-20:0.01:20;
fx=1.5*x.^3-8.1*x.^2+18.6*x-10;
plot(x,fx);
grid on;
P=[1.5 -8.1 18.6 -10];
x_an=roots(P);
x_an=x_an(imag(x_an)==0);
fprintf('analytical root=%7.3f ',x_an);
%----fixed point iteration----%
x=1;
for i=1:1:5
y=(10-1.5*x^3+8.1*x^2)/18.6; %---convert in x=g(x) form----%
x=y;
end
error = (x-x_an)*100/x_an;
fprintf('for fixed point iteration method ');
fprintf('root=%6.3f ',x);
fprintf('percent error=%5.4f ',error);
%-----Newton Raphson Method------%
x=1;
for i=1:1:5
fx=1.5*x^3-8.1*x^2+18.6*x-10;
dfx=4.5*x^2-16.2*x+18.6;
y=x-fx/dfx;
x=y;
end
error = (x-x_an)*100/x_an;
fprintf('for Newton Raphson Method ');
fprintf('root=%6.3f ',x);
fprintf('percent error=%5.4f ',error);
%------Secant Method----%
x0=0;
fx0=1.5*x0^3-8.1*x0^2+18.6*x0-10;
x1=1;
for i=1:1:5
fx1=1.5*x1^3-8.1*x1^2+18.6*x1-10;
x=x1-fx1*(x1-x0)/(fx1-fx0);
fx0=fx1;
x0=x1;
x1=x;
end
error = (x-x_an)*100/x_an;
fprintf('for Secant Method ');
fprintf('root=%6.3f ',x);
fprintf('percent error=%5.4f ',error);
%--------------2nd part---------------%
syms x
I_an=int(x^2*exp(-x));
f1=subs(I_an,{x},{0});
f2=subs(I_an,{x},{3});
I_an=f2-f1;
fprintf('analytical Integral value=%10.7f ',I_an);
%-------Trapezoidal rule-----%
a=0;
b=3;
n=512;
h=(b-a)/n;
x=0;
I=0;
for i=1:1:512
I=I+h*x^2*exp(-x);
x=x+h;
end
error = (I-I_an)*100/I_an;
fprintf('for Trapezoidal rule ');
fprintf('Integral=%10.7f ',I);
fprintf('percent error=%5.4f ',error);
%-------Simpsons 1/3 rule-----%
fa=a^2*exp(-a); % f(a)
fb=b^2*exp(-b); % f(b)
ff=0;
for i=2:2:n; % all 4*f(a+nh) terms to f(b) h=(1,3,5,7,