Matlab spring equation question

조회 수: 9 (최근 30일)
Liam Bouchereau
Liam Bouchereau 2020년 10월 27일
편집: maiaL 2020년 10월 27일
Can someone please help me with the following question?
The force required to compress a linear spring is given by the equation;
where F is the force in newtons, k is the spring constant in newtons per meter and x is displacement. Write a program which will determine the compression of each spring for a given set of forces F and corresponding spring constants k. Use function round() to round the n-th element in the answer vector only.
For example:
TestResult
F = [20 30 80];
k = [20 10 20];
n_th = 2;
Result =
3
  댓글 수: 2
KSSV
KSSV 2020년 10월 27일
You have to use
F = k*x
right? F, k is given.
Liam Bouchereau
Liam Bouchereau 2020년 10월 27일
F = k*x doesn't work because x is undefined
I tried
x = F/k;
disp(round(x));
but am unsure how to round to the n_th element

댓글을 달려면 로그인하십시오.

답변 (1개)

maiaL
maiaL 2020년 10월 27일
편집: maiaL 2020년 10월 27일
The way I understand the problem, you need an array "x" as the result of this program, which will have the same size as the arrays F and k. For that, I would use an element-wise division here:
x = F./k;
For the rounding part, I believe you'd need to use the round() function with a 2nd argument, like so:
x = round(x,n_th);

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by