필터 지우기
필터 지우기

MATLAB question on Chapter 4

조회 수: 4 (최근 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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by