Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to formulate a matlab function that works. I keep getting errors but

ID: 3135225 • Letter: I

Question

I am trying to formulate a matlab function that works. I keep getting errors but am not sure as to why. Could somebody please help me get this code running or refer me to someone that can? That would be much appreciated. (JUST PASTE INTO MATLAB)

function dw_dt = rollerCoasterDE(t, w, pp, u, m, Fm, time_span_m) % SplineDeriv1 and splineDeriv2 codes that are used to model the track at %time t d1 = splineDeriv1(pp, w(1)); d2 = splineDeriv2(pp, w(1)); % Defining the slope of the velocity and shape of the track slope_vel = sqrt( (x_vel)^2 + (y_vel)^2 ); slope = d1; speed = sqrt( w(2)^2 + w(4)^2 ); % Calculating the tangent unit vector by normalizing a tangent vector U_tang = [1, slope]; Un_tang = U_tang ./ norm(U_tang); % Calculating the normal unit vector by normalizing a normal vector U_norm = [-(slope), 1]; Un_norm = U_norm ./ norm(U_norm); %% Calculating the gravitational force- Fg g = 9.8; % m/s^2 Fg = [0, -m*g]; %% Finding the normal force of the car % Firstly, setting up the inverse (K) of the radius of a circle at a point on the non-curved track Kr = d2 / ( (1 + (d1)^2)^(3/2) ); % Computing the net centripetal acceleration tang_vel = speed .* Un_tang; a_n =(( norm(tang_vel))^2)*Kr; % Computing the normal force using the net force (Fn) and normal accel (a_n) Fn_mag = m*a_n - (dot (Fg, Un_norm)); %(Fn - Fg) Fn = Fn_mag.*(Un_norm); %% Checking to see if the motor force is currently being applied if t >= time_span_m(1) && t <= time_span_m(2) Fmotor = Fm.*(Un_tang); else Fmotor = [0,0]; end %% The net force (Fnet), x-accel, y-accel are finally calculated Fnet = Fr + Fn + Fg + Fmotor; x_accel = Fnet(1)/m; y_accel = Fnet(2)/m; %% Assigning final values to the output dw_dt(1,1) = w(2); dw_dt(2,1) = x_accel; dw_dt(3,1) = w(4); dw_dt(4,1) = y_accel;

function dw_dt = rollerCoasterDE(t, w, pp, u, m, Fm, time_span_m) %% SplineDeriv1 and splineDeriv2 codes that are used to model the track at %time t d1 = splineDeriv1(pp, w(1)); d2 = splineDeriv2(pp, w(1)); %% Defining the slope of the velocity and shape of the track slope_vel = sqrt( (x_vel)^2 + (y_vel)^2 ); slope = d1; speed = sqrt( w(2)^2 + w(4)^2 ); %% Calculating the tangent unit vector by normalizing a tangent vector U_tang = [1, slope]; Un_tang = U_tang ./ norm(U_tang); %% Calculating the normal unit vector by normalizing a normal vector U_norm = [-(slope), 1]; Un_norm = U_norm ./ norm(U_norm); %% Calculating the gravitational force- Fg g = 9.8; % m/s^2 Fg = [0, -m*g]; %% Finding the normal force of the car %% Firstly, setting up the inverse (K) of the radius of a circle at a point on the non-curved track Kr = d2 / ( (1 + (d1)^2)^(3/2) ); %% Computing the net centripetal acceleration tang_vel = speed .* Un_tang; a_n =(( norm(tang_vel))^2)*Kr; %% Computing the normal force using the net force (Fn) and normal accel (a_n) Fn_mag = m*a_n - (dot (Fg, Un_norm)); %(Fn - Fg) Fn = Fn_mag.*(Un_norm); %% Checking to see if the motor force is currently being applied if t >= time_span_m(1) && t <= time_span_m(2) Fmotor = Fm.*(Un_tang); else Fmotor = [0,0]; end %% The net force (Fnet), x-accel, y-accel are finally calculated Fnet = Fr + Fn + Fg + Fmotor; x_accel = Fnet(1)/m; y_accel = Fnet(2)/m; %% Assigning final values to the output dw_dt(1,1) = w(2); dw_dt(2,1) = x_accel; dw_dt(3,1) = w(4); dw_dt(4,1) = y_accel;

Explanation / Answer

function dw_dt = rollerCoasterDE(t, w, pp, u, m, Fm, time_span_m) % SplineDeriv1 and splineDeriv2 codes that are used to model the track at %time t d1 = splineDeriv1(pp, w(1)); d2 = splineDeriv2(pp, w(1)); % Defining the slope of the velocity and shape of the track slope_vel = sqrt( (x_vel)^2 + (y_vel)^2 ); slope = d1; speed = sqrt( w(2)^2 + w(4)^2 ); % Calculating the tangent unit vector by normalizing a tangent vector U_tang = [1, slope]; Un_tang = U_tang ./ norm(U_tang); % Calculating the normal unit vector by normalizing a normal vector U_norm = [-(slope), 1]; Un_norm = U_norm ./ norm(U_norm); %% Calculating the gravitational force- Fg g = 9.8; % m/s^2 Fg = [0, -m*g]; %% Finding the normal force of the car % Firstly, setting up the inverse (K) of the radius of a circle at a point on the non-curved track Kr = d2 / ( (1 + (d1)^2)^(3/2) ); % Computing the net centripetal acceleration tang_vel = speed .* Un_tang; a_n =(( norm(tang_vel))^2)*Kr; % Computing the normal force using the net force (Fn) and normal accel (a_n) Fn_mag = m*a_n - (dot (Fg, Un_norm)); %(Fn - Fg) Fn = Fn_mag.*(Un_norm); %% Checking to see if the motor force is currently being applied if t >= time_span_m(1) && t <= time_span_m(2) Fmotor = Fm.*(Un_tang); else Fmotor = [0,0]; end %% The net force (Fnet), x-accel, y-accel are finally calculated Fnet = Fr + Fn + Fg + Fmotor; x_accel = Fnet(1)/m; y_accel = Fnet(2)/m; %% Assigning final values to the output dw_dt(1,1) = w(2); dw_dt(2,1) = x_accel; dw_dt(3,1) = w(4); dw_dt(4,1) = y_accel;

function dw_dt = rollerCoasterDE(t, w, pp, u, m, Fm, time_span_m) %% SplineDeriv1 and splineDeriv2 codes that are used to model the track at %time t d1 = splineDeriv1(pp, w(1)); d2 = splineDeriv2(pp, w(1)); %% Defining the slope of the velocity and shape of the track slope_vel = sqrt( (x_vel)^2 + (y_vel)^2 ); slope = d1; speed = sqrt( w(2)^2 + w(4)^2 ); %% Calculating the tangent unit vector by normalizing a tangent vector U_tang = [1, slope]; Un_tang = U_tang ./ norm(U_tang); %% Calculating the normal unit vector by normalizing a normal vector U_norm = [-(slope), 1]; Un_norm = U_norm ./ norm(U_norm); %% Calculating the gravitational force- Fg g = 9.8; % m/s^2 Fg = [0, -m*g]; %% Finding the normal force of the car %% Firstly, setting up the inverse (K) of the radius of a circle at a point on the non-curved track Kr = d2 / ( (1 + (d1)^2)^(3/2) ); %% Computing the net centripetal acceleration tang_vel = speed .* Un_tang; a_n =(( norm(tang_vel))^2)*Kr; %% Computing the normal force using the net force (Fn) and normal accel (a_n) Fn_mag = m*a_n - (dot (Fg, Un_norm)); %(Fn - Fg) Fn = Fn_mag.*(Un_norm); %% Checking to see if the motor force is currently being applied if t >= time_span_m(1) && t <= time_span_m(2) Fmotor = Fm.*(Un_tang); else Fmotor = [0,0]; end %% The net force (Fnet), x-accel, y-accel are finally calculated Fnet = Fr + Fn + Fg + Fmotor; x_accel = Fnet(1)/m; y_accel = Fnet(2)/m; %% Assigning final values to the output dw_dt(1,1) = w(2); dw_dt(2,1) = x_accel; dw_dt(3,1) = w(4); dw_dt(4,1) = y_accel;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote