-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ22_PathDistance.m
More file actions
58 lines (50 loc) · 2.33 KB
/
Q22_PathDistance.m
File metadata and controls
58 lines (50 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% =========================================================================================
% FILE NAME: Q22_PathDistance.m
% AUTHOR: [Amey Thakur](https://github.com/Amey-Thakur)
% COURSE REPO: https://github.com/Amey-Thakur/COMPUTATIONAL-METHODS-AND-MODELING-FOR-ENGINEERING-APPLICATIONS
% RELEASE DATE: September 08, 2023
% LICENSE: Creative Commons Attribution 4.0 International (CC BY 4.0)
%
% DESCRIPTION:
% This script computes the distance of closest approach between a ship traveling on a
% straight-line course and a lighthouse located at the origin (0,0).
% The course is defined by the linear equation y = (200 - 5x) / 6.
%
% PROBLEM STATEMENT (Q22):
% A ship travels on a straight line course described by y = (200 - 5x) / 6,
% where distances are measured in kilometers. The ship starts when x = -20
% and ends when x = 40. Calculate the distance at closest approach to a
% lighthouse located at the coordinate origin (0,0).
%
% MATHEMATICAL MODEL:
% 1. Distance squared: D^2 = x^2 + y^2
% 2. Substitution: D^2 = x^2 + [ (200 - 5x) / 6 ]^2
% 3. Optimization: Find x that minimizes D (or D^2) within x \in [-20, 40].
%
% Reference: MATLAB for Engineering Applications, William J. Palm, Chapter 2, Q22.
%
% TECHNOLOGY STACK:
% - Programming Language: MATLAB (R2023a+)
% =========================================================================================
% --- Environment Initialization ---
clc;
clear;
% --- Domain Definition ---
% Defined ship interval for x
x_domain = linspace(-20, 40, 1000);
% --- Computational Analysis ---
% a. Define the course path y(x)
y_path = (200 - 5 * x_domain) / 6;
% b. Calculate the distance (D) from origin (0,0) to each point (x, y)
% D = sqrt( x^2 + y^2 )
distance = sqrt( x_domain.^2 + y_path.^2 );
% c. Find the minimum distance and the corresponding location
[min_distance, min_index] = min(distance);
closest_x = x_domain(min_index);
closest_y = y_path(min_index);
% --- Results Visualization ---
fprintf('--- Ship-to-Lighthouse Proximity Analysis ---\n');
fprintf('Closest Approach Distance: %8.4f km\n', min_distance);
fprintf('Coordinate of Closest Approach: (x = %8.4f, y = %8.4f)\n', closest_x, closest_y);
% Professional Scholarly Footer
fprintf('\nNavigational Insight: The closest approach is geometrically defined by the perpendicular projection of the origin onto the linear course path.\n');