How to convert this equation to MATLAB code?
古いコメントを表示

I am having difficulty writing this long equation into matlab code, please advise
8 件のコメント
John D'Errico
2020 年 9 月 24 日
編集済み: John D'Errico
2020 年 9 月 24 日
While need not be explicitly homework, it is sure;y part of some project, assigned to you. So why not try something? You might learn something along the ay, and then someone can show you how to fix it.
I'll give you a hint, in that since you have written tan(30), you probably need to know how to use the tan and cos functions that work with degrees. Thus
help tand
help cosd
So TRY IT! If you absolutely have no clue how to use MATLAB, then you need to read the manual. Better yet, try the MATLAB OnRamp tutorial.
Very close!
One critical mistake.
- This section is wrong. You're doing A/B*C but that's not how that part of the equation is defined.
(((x1.^2)*9.81)/25*(cos(30)))
% -------A------ B ----C----
Two cautionary comments
- Are you sure the last constant is 3.5 rather than 35?
- The "cos(30)" and "tan(30)" in the equation is likely in reference to degrees so you'll either need to convert 30deg to radians (see deg2rad) or use cosd() & tand() which receives degree inputs.
Some very minor points
- No need for the outer brackets
- The brackets here are unnecessary but if they help you, that's totally fine: (x1.^2)*9.81; You can review Matlab's Operator Precedence.
- No need for these outer brackets, they are confusing: (cos(30))
- There's no need for the outer brackets aound the fraction that contains parentheses in the image you shared but, as with point #2, sometimes those brackets are helpful for perceptual grouping and I would probably keep them.
Result
After making those changes, including the interpretation of degrees and that the constant at the end is 35, the first few elements of the row-vector outptut are
y1 = [ 35 35.155 35.268 35.339 , ...
Adam Danz
2020 年 9 月 24 日
When I change 35 to 3.5 the first 5 outputs are
3.5 3.655 3.7678 3.8386 3.8672
JM
2020 年 9 月 24 日
Adam Danz
2020 年 9 月 24 日
Sounds like you figured it out! Socially distant 3-way high-five!
Rik
2021 年 4 月 20 日
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Historical Contests についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!