Question: I will run the following MATLAB code: clc; clear; clf; x0 = 1.2; y0 = 0; % initial position of spaceship (normalized units) vx0 =
I will run the following MATLAB code:
clc; clear; clf;
x0 = 1.2; y0 = 0; % initial position of spaceship (normalized units)
vx0 = 0; vy0 = -1.0493571; % initial velocity of spaceship (normalized units)
t0 = 0; tf = 10; % initial time, final time (normalized units)
fd = 0 % deceleration coefficient
N = 10000; % initial guess for number of time steps
dt = (tf-t0)/N; % dt = time step (normalized units)
eps = 0.01; % termination criteria
% I will adjust the parameters above when grading your assignment
[x,y,vx,vy,t] = myrk4(t0,tf,dt,x0,y0,vx0,vy0,fd,eps);
% You will need to write an RK4 solver in a separate M-file named myrk4.m
% x and y are the coordinates of the spaceship at each time step
% vx and vy are the x and y components of the speed at each time step
disp(['The final (x,y) position is: (' num2str(x(end)) ',' num2str(y(end)) ')'])
Your job is to create an M-file named myrk4.m that contains a function named myrk4. This function calculates the position and speed at every time step using the RK4 method. The outline of your M-file is the following:
function [x,y,vx,vy,t] = myrk4(t0,tf,dt,x0,y0,vx0,vy0,f,eps);
% Place your solver here
% After your solver is finished and you know the trajectory and velocity, write code that will plot trajectory and phase space on two subplots. Be sure to add labels so the user will know what the axes represent.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
