Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Hi; Can you help me to find fault?
1 回表示 (過去 30 日間)
古いコメントを表示
Write a function called sindeg that takes a matrix input called deg. The function returns a matrix of the same size as deg with each of its elements containing the sine of the corresponding element of deg. Note that the elements of deg are given in degrees and not radians. As a second output, the function returns a scalar that contains the average value of the first output. You are not allowed to use the sind and cosd built-in functions, but the use of any other function is acceptable.
My answer is;
function [sine, mean_sine] = sindeg(deg)
sine = (exp(i*deg) - exp(-i*deg))/(2i);
mean_sine = sum(sine) / length(deg);
The fault;
Problem 2 (sindeg):
Testing with argument(s) [0 90 180]
Feedback: Your function made an error for argument(s) [0 90 180]
Your solution is _not_ correct.
I dont understand this feedback. When I try this feedback format, solution is correct too.
1 件のコメント
回答 (1 件)
Andrei Bobrov
2017 年 10 月 30 日
編集済み: Andrei Bobrov
2017 年 10 月 30 日
function [y, mean_sine] = sindeg(deg)
xx = deg/180*pi;
y = (exp(1i*xx) - exp(-1i*xx))/(2i);
mean_sine = sum(y(:)) / numel(deg);
end
5 件のコメント
Vaibhav Sharma
2018 年 2 月 4 日
You are a god man !! i am in 6 th class and i have started programming with matlab and i was also stuck on this problem. i heard the name sin for the first time in my life you can figure how difficult it was for me i just needed the fixed version as i was doing the same mistake as shown before
Jan
2018 年 2 月 4 日
@Vaibhav Sharma: Please stop creating flags to post a comment. Flags are thought to inform the admins or editors about a message, which might conflict with the terms of use, e.g. due to rudeness.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!