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

Hw-3 Your task is to calculate and update the speed of position of a vehicle and

ID: 1717148 • Letter: H

Question

Hw-3 Your task is to calculate and update the speed of position of a vehicle and acceleration at time 0 of vehicle are given in 2 Dimensions as, Initial Position (2, 2) m Initial Velocity (1.5, 3) m/s Initial accel 2 m/s 2. 1) Ask if user wants to run the vehicle on the random track. 2) Create a function to use in main program which creates a random path within the boundaries of X 10 10, and Y 10 10. Update the position vectors with newly created path 3) Create another function which calculates the velocity of vehicle according to newly created random path. Call both functions in main program to use. 4) Plot the vehicle path in 2D. Plot velocity magnitude.

Explanation / Answer

The main function;

%clearing window, variables and figures
clear all;
close all;
clf;
clc;
t=0:.001:1;
l=length(t);
a=2;
vy=3;
vx=1.5;
c=input(' Do you want to run the vehicle on random track, press 1 if yes: ');
if c==1
x1=randm(-10,10,l);
y1=randm(-10,10,l);
fprintf(' The velocity along y side :');
vy=vel(y1,t);
fprintf(' The velocity along x side :');
vx=vel(x1,t);
for i=1:1:l
x(:,i)=x1(i);
end
for i=1:1:l
y(:,i)=x1(i);
end
figure
plot(x,y);
title('y vs x');
else
y(:,1)=2;
x(:,1)=2;
for i=2:1:l
y(:,i)=y(:,1)+vy*t(:,i)+0.5*a*t(:,i)^2;
x(:,i)=x(:,1)+vx*t(:,i)+0.5*a*t(:,i)^2;
end
plot(x,y)
title('y vs x');
end

The function to create random path, randm.m;

function v=randm(l1,u1,l)
s=randn(l,1);
for i=1:1:l
if(s(i)<l1 && s(i)>u1)
s(i)==0
end
end
v=s;

The function to calculate velocity, vel.m;

function v=vel(e,t)
l=length(t);
for i=1:1:l-1
v(:,i)=(e(i+1)-e(i))/(t(:,i+1)-t(:,i));
t1(:,i)=i*(t(:,i+1)-t(:,i));
end
figure
plot(t1,abs(v))
title('v vs t')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote