MATLAB question on Chapter 4

5 ビュー (過去 30 日間)
Miriam Marroquin
Miriam Marroquin 2020 年 9 月 17 日
コメント済み: Miriam Marroquin 2020 年 9 月 26 日
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 件のコメント
Miriam Marroquin
Miriam Marroquin 2020 年 9 月 17 日
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.

サインインしてコメントする。

回答 (1 件)

Madhav Thakker
Madhav Thakker 2020 年 9 月 22 日
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 件のコメント
Miriam Marroquin
Miriam Marroquin 2020 年 9 月 26 日
Thanks for the guidance, I forgot about the element-by-element operation!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by