Write a function that is called like this: amag = accelerate(F1,F2,m). F1 and F2 are three-element column vectors that represent two forces applied to a single object. The argument m equals the mass of the object in units of kilograms. The three elements of each force equal the x, y, and z components of the force in Newtons. The output variable amag is a scalar that is equal to the magnitude of the object’s acceleration. The function calculates the object’s acceleration vector a by using Newton’s law: F = ma, where F is the sum of F1 and F2. Then it returns the magnitude of a. Hint: we are talking about physical vectors here, so the Pythagorean theorem will come in handy.
this was my function:
function a = accelerate(F1,F2,m)
Fa = sqrt(((F1(1,1))^2)+((F1(2,1))^2)+((F1(3,1))^2));
Fb = sqrt(((F2(1,1))^2)+((F2(2,1))^2)+((F2(3,1))^2));
Ft = Fa + Fb;
a = Ft/m;
end
Upon using the function checker it gives the feedback:
Feedback: Your function performed correctly for argument(s) [1;0;0], [0;0;0], 1
Feedback: Your function performed correctly for argument(s) [1;0;0], [1;0;0], 1
Feedback: Your function performed correctly for argument(s) [0;1;0], [0;1;0], 1
Feedback: Your function performed correctly for argument(s) [0;0;1], [0;0;1], 1
Feedback: Your function made an error for argument(s) [1;0;0], [0;1;0], 1
Your solution is _not_ correct.
Help.

댓글 수: 2

Stephen23
Stephen23 2018년 6월 4일
편집: Stephen23 2018년 6월 4일
Tip: rather then writing this (with confusing parentheses):
sqrt(((F1(1,1))^2)+((F1(2,1))^2)+((F1(3,1))^2))
it is much simpler to just do this:
sqrt(sum(F1.^2))
Note: your code does not sum the vector forces properly. As this is homework I will not solve it for you, but you can find plenty of tutorials online that show how to sum vector forces.
Aakash Deep
Aakash Deep 2018년 6월 4일
It is working fine. I checked it, it is not giving any error.

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

답변 (1개)

Torsten
Torsten 2018년 6월 4일

0 개 추천

Shouldn't it be
function a = accelerate(F1,F2,m)
F = F1 + F2;
a = norm(F)/m;
end
?
Best wishes
Torsten.

카테고리

도움말 센터File Exchange에서 Power and Energy Systems에 대해 자세히 알아보기

질문:

2018년 6월 4일

댓글:

2018년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by