Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Hi; Can you help me to find fault?

2 vues (au cours des 30 derniers jours)
SULE SAHIN
SULE SAHIN le 30 Oct 2017
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaire
Walter Roberson
Walter Roberson le 27 Avr 2018
Please do not close questions that have an answer.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 30 Oct 2017
Modifié(e) : Andrei Bobrov le 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 commentaires
Vaibhav Sharma
Vaibhav Sharma le 4 Fév 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 le 4 Fév 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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by