-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ34_LawOfCosines.m
More file actions
65 lines (55 loc) · 2.43 KB
/
Q34_LawOfCosines.m
File metadata and controls
65 lines (55 loc) · 2.43 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
59
60
61
62
63
64
65
% =========================================================================================
% FILE NAME: Q34_LawOfCosines.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 implements a geometric solver based on the Law of Cosines to calculate
% side lengths in a quadrilateral composed of two adjacent triangles.
%
% PROBLEM STATEMENT (Q34):
% The four-sided figure shown in Figure P34 consists of two triangles having a
% common side a. Develop a procedure for computing the length of side c2 if you
% are given the lengths of sides b1, b2, and c1 and the angles A1 and A2 in degrees.
% Test your script using: b1 = 200m, b2 = 180m, c1 = 120m, A1 = 120, and A2 = 100.
%
% MATHEMATICAL MODEL:
% Law of Cosines: a^2 = b^2 + c^2 - 2*b*c*cos(A)
%
% Reference: MATLAB for Engineering Applications, William J. Palm, Chapter 1, Q34.
%
% TECHNOLOGY STACK:
% - Programming Language: MATLAB (R2023a+)
% =========================================================================================
% --- Environment Initialization ---
clc;
clear;
% --- Input Dataset (Figure P34) ---
% Side lengths (meters)
b1 = 200;
b2 = 180;
c1 = 120;
% Internal Angles (Degrees)
A1 = 120;
A2 = 100;
% --- Computational Analysis ---
% 1. Compute common side 'a' using the top triangle properties
% Degrees to Radians conversion is required for MATLAB's cosD function or manual cos(A*pi/180)
a_squared = b1^2 + c1^2 - 2 * b1 * c1 * cosd(A1);
a = sqrt(a_squared);
% 2. Compute side 'c2' using the bottom triangle properties (given sides a, b2 and angle A2)
% a^2 = b2^2 + c2^2 - 2*b2*c2*cos(A2)
% Rearranged as a quadratic equation in terms of c2:
% c2^2 - (2*b2*cos(A2))*c2 + (b2^2 - a^2) = 0
coeff_quadratic = [1, -2 * b2 * cosd(A2), (b2^2 - a^2)];
roots_c2 = roots(coeff_quadratic);
% Select the positive physical root
c2 = roots_c2(roots_c2 > 0);
% --- Results Visualization ---
fprintf('--- Geometric Quadrilateral Analysis ---\n');
fprintf('Common Internal Side (a): %8.4f m\n', a);
fprintf('Target External Side (c2): %8.4f m\n', c2);
% Professional Scholarly Footer
fprintf('\nStructural Insight: The quadratic solution for side c2 represents the geometric constraint of the triangular closure. Negative roots are non-physical and discarded.\n');