# MATLAB question on Chapter 4

9 views (last 30 days)
Miriam Marroquin on 17 Sep 2020
Commented: Miriam Marroquin on 26 Sep 2020
How I find the minimum length of the cord?
I figured out how to get the equation however, when I write in MATLAB I cannot seem to get a response since x is an array
This is what I have so far:
%% Problem 10
%Create x
% Let H1 = x
x = [50:0.1:200];
H1 = x;
% Creating an array that ranges from 50 to 200 with increments of 0.1
% We do this because the image shows us that the length of the cable for
% house1 (H1) cannot be more than 210 ft
% We know want to find the lenght of house2 and 3 (H2 & H3).
% The image shows us that we can form a triangle at the corner of H2 and
% H3.
% The length between the two is 210 -x and the height of each starting at
% the 210-x length is 80ft
% So we will use the pythagorean theorem to find the missing side for H2
% and H3
% Note that both H2 and H3 have the same dimensions so we will use one
% equation and double it.
% H2= H3= y = sqrt(80^2 + (210-H1)^2)
y = sqrt(80^2 + (210-H1)^2);
% To find the total length
total = H1 + 2* sqrt(80^2 + (210-H1)^2)

#### 1 Comment

Miriam Marroquin on 17 Sep 2020
Here is the question:
The electricity supply cables of the three houses shown are connected to a pole as shown. Write a MATLAB program that determines the location of the pole (distance x) that minimizes the total length of the cables needed. In the program define a vector x with values ranging from 50 to 200 with increments of 0.1. Use this vector to calculate the corresponding values of total length of the cables. Then use MATLAB’s built-in function min to find the value of x that corresponds to the shortest length of cables.

Madhav Thakker on 22 Sep 2020
Hi Miriam,
The variable H1 is a matrix of size [1, 1501] and the command
y = sqrt(80^2 + (210-H1)^2);
tries to multiply a matrix of size [1. 1501] with itself, which throws an error. What you instead need to do is take the square of each element for which you can use dot operator. Example -
y = sqrt(80^2 + (210-H1).^2);
total = H1 + 2* sqrt(80^2 + (210-H1).^2)
min(total)
Hope this helps.

#### 1 Comment

Miriam Marroquin on 26 Sep 2020
Thanks for the guidance, I forgot about the element-by-element operation!