9 views (last 30 days)

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)

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.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/595600-matlab-question-on-chapter-4#comment_1013428

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/595600-matlab-question-on-chapter-4#comment_1013428

Sign in to comment.