Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Hi; Can you help me to find fault?

2 views (last 30 days)
SULE SAHIN
SULE SAHIN on 30 Oct 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comment
Walter Roberson
Walter Roberson on 27 Apr 2018
Please do not close questions that have an answer.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 30 Oct 2017
Edited: Andrei Bobrov on 30 Oct 2017
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 Comments
Vaibhav Sharma
Vaibhav Sharma on 4 Feb 2018
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
Jan on 4 Feb 2018
@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.

This question is closed.

Community Treasure Hunt

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

Start Hunting!