← Back
ExercisesComplete set

Notes for exercises

Study material for Mathematical and Numerical Methods in Engineering, shared by the Studwiz community and reviewed by moderators.

Mathematical and Numerical Methods in EngineeringComplete set

Document information

What's included in this study material

Study material for Mathematical and Numerical Methods in Engineering, shared by the Studwiz community and reviewed by moderators.

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

NOTES FOR EXERCICES M&N METHODS – NUMERICAL PART MATLAB EXERCICES Order of accuracy: 𝑝=log!&"##(%,'()!"##*"#,$%#+!&'' , 𝑒𝑟𝑟,=|𝑢,−𝑢"-./((𝑥,)| i=1,…,M-1 are NOT the nodes but the halvings of the discretization step h for j = 1:M [t, u] = method(t0, tf, u0, dt, lambda,…); e(j) = max( abs(u – u_ex) ); dt = dt/2; end p = log2( e(1:end-1) ./ e(2:end) ); Transport eq.: • FE/C unew(2:(Nh-1)) = u(2:Nh-1) - CFL/2*( u(3:Nh) - u(1:Nh-2) ) % Boundary condition unew(1) = Uinflow; % Inflow unew(Nh) = (1-CFL)*u(Nh) + CFL*u(Nh-1); % Outflow (UW) • BE/C A = speye(Nh-1) + spdiags([-e, e], [-1, 1], Nh-1, Nh-1); for n = 1:Nt-1 t = t+dt; F(2:Nh-1) = u(3:Nh); F(1) = u(2) + 0.5*a*lambda*Uinflow; % BE step unew(2:Nh) = A\F; unew(1) = Uinflow; end • Upwind unew(2:Nh) = (1-CFL)*u(2:Nh) + CFL*u(1:Nh-1); % Boundary condition unew(1) = Uinflow; % Inflow • Lax-Friedrich unew(2:Nh-1) = 1/2*(u(3:Nh)+u(1:Nh-2)) - CFL/2*(u(3:Nh) - u(1:Nh-2)) % Boundary condition unew(1) = Uinflow; % Inflow unew(Nh) = (1-CFL)*u(Nh) + CFL*u(Nh-1); % Outflow • Lax-Wendroff k = a^2 * dt^2 unew(2:(Nh-1)) = u(2:Nh-1) - CFL/2 * ( u(3:Nh) - u(1:Nh-2) ) ... + k/(2*h^2) * ( u(3:Nh) - 2*u(2:Nh-1) + u(1:Nh-2) ) % Boundary condition unew(1) = Uinflow; % Inflow unew(Nh) = (1-CFL)*u(Nh) + CFL*u(Nh-1); % Outflow N.B. In LW scheme: Upwind: k = abs(a) * h * dt Law-Friedrich: k = h^2 Heat eq.: A = (h^(-2))*spdiags([-e, 2*e, -e], [-1, 0, 1], M-1, M-1); % Initial and boundary conditions u(:, 1) = y0(x, t0); u(1, :) = 0; u(end, :) = 0; % Theta method applied to the internal nodes I = speye(M-1); for n = 1:N u(2:end-1, n+1) = ... (I + dt*theta*A) \ ((I - dt*(1-theta)*A)*u(2:end-1, n)); end • FE theta = 0 • BE theta = 1 • CN theta = 1/2 Poisson eq.: • Dirichlet BC A = spdiags([-e, 2*e, -e], [-1, 0, 1] , M-1, M-1)/(h^2); F = f(x(2:end-1))';…

Preview

First page of the document.

First page: Notes for exercises