Matelab and latex professional report

profileDLLM
bouncing_ball_in_class.m

% Outline of the code simulating a ball in a closed container using the % Euler method (it is not a complete code and does not run) clear; % boundaries of the container a = 0; b = 1; c = 0; d = 1; % damping coefficients alpha = 0.8; beta = 0.9; % free-fall acceleration g = 9.81; % radius of the ball r = 0.05; % right hand side f_x = @(t,x,y,vx,vy) vx; f_y = @(t,x,y,vx,vy) ...; f_vx = @(t,x,y,vx,vy) ...; f_vy = @(t,x,y,vx,vy) ...; % initial conditions t_start = 0; x_start = 0.1; y_start = 0.7; vx_start = 3; vy_start = 1; % final time and time-step t_final = 2.5; dt = 0.01; % impose initial conditions t = t_start; x_old = x_start; y_old = y_start; vx_old = vx_start; vy_old = vy_start; % Exact solution at the final time (doesn't work for more than three bounces) [x_exact, y_exact, vx_exact, vy_exact] = bouncing_ball_exact(t_final,a,b,c,d,r,g,alpha,beta,x_start,y_start,vx_start,vy_start); % auxiliary arrays to plot the trajectory x_all = x_start; y_all = y_start; while t < t_final dt_now = dt; if t + dt > t_final dt_now = t_final-t; end % Euler step x_new = x_old + dt_now*f_x(t, x_old, y_old, vx_old, vy_old); y_new = ... vx_new = ... vy_new = ... % check for a collision with the right wall if x_new > b-r dt_now = dt*(b-r-x_old)/(x_new-x_old); x_new = x_old + dt_now*f_x(t, x_old, y_old, vx_old, vy_old); y_new = ... vx_new = ... vy_new = ... vx_new = -alpha*vx_new; vy_new = beta*vy_new; end % save trajectory points to make plots x_all = [x_all x_new]; y_all = [y_all y_new]; % plot the ball and its trajectory draw_disk(x_new, y_new, r); axis([a b, c d]); axis square; hold on plot(x_all, y_all,'.-'); hold off pause(dt); % advance time t = t+dt_now; % prepare values for next iteration x_old = x_new; y_old = y_new; vx_old = vx_new; vy_old = vy_new; end