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

Using matlab 4) [EULER LEAF – on-going] In last week’s homework you moved one pa

ID: 665510 • Letter: U

Question

Using matlab

4) [EULER LEAF – on-going] In last week’s homework you moved one particle multiple steps.In this week’s homework you’re going to move a single particle multiple steps, but with differentstep sizes. You’re also going to use a function to calculate one step of the integration. Step sizes: Use step sizes of 0.05, 0.1, and 0.2. Each step size should be plotted on its own row inthe figure. Use a for loop here – do not copy code. As before, you should integrate for a total of3 seconds; this means that each row of plots will have a different number of points.Function: Create a function file to do one integration step. This function takes in x, v, m, and h.Put your force function calculation in the function file. Return the new x, the new v, and f (returnthe force, f, so that you can plot it). You must use a function file, and the force calculation mustbe in that function file, not in the calling script.Creating the plots: Create the same plots as before. You will need to store the x, v, and f values inorder to plot them (the extra credit part from last week). You should be calling plot exactly oncefor each plot.

Previous script supplementary

%clear command window, and variables
clc;
clear;

%defining given variables
x=0; %meters
v=0.5; %meters/second
m=0.3; %kilograms
h=0.05; %seconds
t=3 ;%seconds
%the variable a calculates how many 0.05s steps need to be taken to total 3
%seconds
a=t/h;


%F=The force acting on the leaf, represented by a function of x
%a=the acceleration represent by a the division of the force over the mass
% variable x representing (x') defining the position in meters
%variable v represent(v') defining the velocity in meters/second
%creating for loop to calculate the positions for 0.05 second steps from 0
%to 3 seconds
x_=zeros;
for k=1:a;
x=x+(h*v);
F=(0.2*sin(x))*((x.^2)+x);
a=F/m;
v=v+(h*a);
x_(k)=x;
F_(k)=F;
v_(k)=v;
end

%print the values of x_ and v_ in the output
fprintf('the postion after multiple 0.05 second steps for 3 seconds ')
fprintf('x= %0.4f ',x)

%creating a vector t from 1-3 seconds thats is the same length of the
%elements of the positions vector x_. ( the same for force and velocity)
t_=linspace(0,3,length(x_));

%creating a 1x3 subplot to plot 3 plots in one display
%plot of time vs position
subplot(1,3,1)
plot(t_,x_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('particle moving in vector field')

%plot of time vs velocity
subplot(1,3,2)
plot(t_,v_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('velocity of particle')

%plot of time vs Force
subplot(1,3,3)
plot(t_,F_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('Force of particle')

Explanation / Answer

The code remains almost the same. Only change is done to h=0.1 to calculates how many 0.1s steps need to be taken to total 3 seconds.

%clear command window, and variables
clc;
clear;

%defining given variables
x=0; %meters
v=0.5; %meters/second
m=0.3; %kilograms
h=0.1; %seconds
t=3 ;%seconds
%the variable a calculates how many 0.1s steps need to be taken to total 3 seconds
a=t/h;


x_=zeros;
for k=1:a; %creating for loop to calculate the positions for 0.1 second steps from 0 to 3 seconds
x=x+(h*v);
F=(0.2*sin(x))*((x.^2)+x);
a=F/m;
v=v+(h*a);
x_(k)=x;
F_(k)=F;
v_(k)=v;
end

%print the values of x_ and v_ in the output
fprintf('the postion after multiple 0.1 second steps for 3 seconds ')
fprintf('x= %0.4f ',x)

%creating a vector t from 1-3 seconds thats is the same length of the
%elements of the positions vector x_. ( the same for force and velocity)

t_=linspace(0,3,length(x_));

%creating a 1x3 subplot to plot 3 plots in one display
%plot of time vs position
subplot(1,3,1)
plot(t_,x_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('particle moving in vector field')

%plot of time vs velocity
subplot(1,3,2)
plot(t_,v_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('velocity of particle')

%plot of time vs Force
subplot(1,3,3)
plot(t_,F_,'o')
xlabel('time step(seconds)')
ylabel('positions (meters)')
title('Force of particle')

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