Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help with converting this code to use linspace command and form a vector

조회 수: 1 (최근 30일)
Lucas Kimmel
Lucas Kimmel 2016년 2월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
I just need help getting started with this question Here is the question: Use the linspace command to formulate a vector ShorexPt, with 11 possible x-entry points into the water. The starting point of the vector is LifeGuardx and the final point is Swimmerx. Also, set ShoreyPt = 0. We are only going to optimize the x-position of entry.
% lifeguard.m
clear; % clear any previously defined variables,
clc; % clear the screen in command window
close all ; % close any figures
figure; % get a blank graphics window
xmax = 5 ;
xmin = 0 ;
ymax = 0.5 ;
x=[xmin,xmax];
y=[0,0] ;
plot(x,y), hold on ;
xlabel('\itkm \color{blue}\itWater '); ylabel('\itkm '); ...
title(' \color[rgb]{.5 .5 .2}\it Land');
axis([xmin, xmax, -ymax, ymax]); % define plot limits
x = rand(2,1);
y = ymax * rand(2,1) ;
LifeGuardx = x(1) ;
LifeGuardy = y(1) ;
Swimmerx = xmax-x(2) ;
Swimmery = -y(2) ;
plot(LifeGuardx,LifeGuardy,'x',Swimmerx,Swimmery,'o'), hold on ;
fprintf('\nClick two points on horizontal line in figure.\n');
%Input Point 1
[ShorexPt1,ShoreyPt1,button] = ginput(1);
plot(ShorexPt1,ShoreyPt1,'ro')
%Calculating the distance from lifeguard to shore
DistkmShorePt1 = sqrt((ShorexPt1 - LifeGuardx)^2 + (ShoreyPt1 - LifeGuardy)^2), disp('km')
DistmilesShorePt1 = (DistkmShorePt1 * 0.6241), disp('mi');
%Calculating the distance from shore to swimmer
DistkmSwimmerPt1 = sqrt((ShorexPt1 - Swimmerx)^2 + (ShoreyPt1 - Swimmery)^2), disp('km');
DistmilesSwimmerPt1 = (DistkmSwimmerPt1 * 0.6241), disp('mi');
%Calculation time for the lifeguard to reach the swimmer
TimePt1 = (DistmilesShorePt1 * 7), disp('min')
TimePt2 = (DistmilesSwimmerPt1 * 60), disp('min')
TotalTime1 = TimePt1 + TimePt2
%Input Point 2
[ShorexPt2,ShoreyPt2,button] = ginput(1);
plot(ShorexPt2,ShoreyPt2,'go')
%Calculating the distance from lifeguard to shore
DistkmShorePt2 = sqrt((ShorexPt2 - LifeGuardx)^2 + (ShoreyPt2 - LifeGuardy)^2), disp('km')
DistmilesShorePt2 = (DistkmShorePt2 * 0.6241), disp('mi');
%Calculating the distance from shore to swimmer
DistkmSwimmerPt2 = sqrt((ShorexPt2 - Swimmerx)^2 + (ShoreyPt2 - Swimmery)^2), disp('km');
DistmilesSwimmerPt2 = (DistkmSwimmerPt2 * 0.6241), disp('mi');
%Calculation time for the lifeguard to reach the swimmer
TimePt3 = (DistmilesShorePt2 * 7), disp('min')
TimePt4 = (DistmilesSwimmerPt2 * 60), disp('min')
TotalTime2 = TimePt3 + TimePt4
%Input Point 3
[ShorexPt3,ShoreyPt3,button] = ginput(1);
plot(ShorexPt3,ShoreyPt3,'bo')
%Calculating the distance from lifeguard to shore
DistkmShorePt3 = sqrt((ShorexPt3 - LifeGuardx)^2 + (ShoreyPt3 - LifeGuardy)^2), disp('km')
DistmilesShorePt3 = (DistkmShorePt3 * 0.6241), disp('mi');
%Calculating the distance from shore to swimmer
DistkmSwimmerPt3 = sqrt((ShorexPt3 - Swimmerx)^2 + (ShoreyPt3 - Swimmery)^2), disp('km');
DistmilesSwimmerPt3 = (DistkmSwimmerPt2 * 0.6241), disp('mi');
%Calculation time for the lifeguard to reach the swimmer
TimePt5 = (DistmilesShorePt3 * 7), disp('min')
TimePt6 = (DistmilesSwimmerPt3 * 60), disp('min')
TotalTime3 = TimePt5 + TimePt6
if TimePt1 < TimePt2
plot([LifeGuardx, ShorexPt1], [LifeGuardy,ShoreyPt1]);
plot([Swimmerx, ShorexPt1], [Swimmery,ShoreyPt1]);
end
  댓글 수: 3
Stephen23
Stephen23 2016년 2월 24일
편집: Stephen23 2016년 2월 24일
@Lucas Kimmel: The text was there, you just formatted it poorly. I fixed it for you. For future questions or comments read these:
Lucas Kimmel
Lucas Kimmel 2016년 2월 29일
편집: Lucas Kimmel 2016년 2월 29일
@Stephen Cobeldick Thanks for the formatting tip. Any idea on help for this question?

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by