How would I type this function correctly?

15 ビュー (過去 30 日間)
John
John 2022 年 12 月 27 日
編集済み: Image Analyst 2022 年 12 月 27 日
How would I type this correctly into matlab? This is what I came up with but it doesn't work.
(atan(2)+log7(150)-4sqrt(88))/((abs)sin(4)-1.4^1.4)

採用された回答

the cyclist
the cyclist 2022 年 12 月 27 日
編集済み: the cyclist 2022 年 12 月 27 日
I guess it is fair to say that you have not really learned basic MATLAB syntax at all.
I would recommend starting to learn the basics by going through the free MATLAB Onramp tutorial. If you don't start learning, then you will need to ask every MATLAB coding question here, forever.
That being said, here are the main things that you need to fix in your code:
There is no log7() function in MATLAB. It has logs for base 2, e, and 10. But you can use the rules of logarithms to get what you want:
x = 150;
log(x) / log(7)
ans = 2.5750
There is no function to take the 4th root of a value. But you can just do this as the 1/4 power:
x = 88;
x^(1/4)
ans = 3.0628
Because you wanted the absolute value of the sum of the two terms, you should have written
abs(sin(4)-1.4^1.4)
ans = 2.3585
Now, maybe you can put this all together?
  3 件のコメント
John D'Errico
John D'Errico 2022 年 12 月 27 日
編集済み: John D'Errico 2022 年 12 月 27 日
+1 of course, but with a couple of comments. 4th root can be obtained from the nthroot function.
nthroot(16,4)
ans = 2
Oh, and be careful, in that too often new users don't realize that sin assumes RADIANS for an argument. So is that 4 meant to be degrees, or radians?
sin(4) % radians
ans = -0.7568
sind(4) % degrees
ans = 0.0698
It very much matters. You use sind and cosd (and atand, etc.) for degree inputs. Or you can convert radians to degrees or the other way around. It is just a scale factor of 180/pi for the transformation.
the cyclist
the cyclist 2022 年 12 月 27 日
編集済み: the cyclist 2022 年 12 月 27 日
Today I learned the nthroot function. Thanks for adding the additional info. It's easy to forget the simple assumptions.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 12 月 27 日
編集済み: Image Analyst 2022 年 12 月 27 日
@John To write this:
try this:
logTerm = log(150) / log(7); % Same as log to the base 7 of 150.
numerator = atan(2) + logTerm - nthroot(88, 4);
denominator = abs(sin(4) - 1.4 ^ 1.4);
output = numerator / denominator
output = 0.2626
To learn other fundamental concepts, invest 2 hours of your time here:

カテゴリ

Help Center および File ExchangeInstall Products についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by