필터 지우기
필터 지우기

Write a function called sindeg that takes a matrix input called deg. The function returns a matrix of the same size as deg with elements containing the sine of the corresponding element of deg and mean of the sine.we are nor allowed builtin functions

조회 수: 1 (최근 30일)
function [sine,mean_sine] = sindeg(deg)
sine = (exp(i*deg) - exp(-i*deg))/(2i)
mean_sine=sine/length(deg)
I am not getting right value. instead I am getting this. sine = 0.1060 -0.2624 0.5514 0.6702 0.5514 0.9866 -0.9483 mean_sine = 0.0151 -0.0375 0.0788 0.0957 0.0788 0.1409 -0.1355 ans = 0.1060 -0.2624 0.5514 0.6702 0.5514 0.9866 -0.9483
  댓글 수: 1
Jan
Jan 2017년 5월 17일
Whenever you write "not getting the right values", mention what the rigth values are and why you assume this.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2017년 5월 17일
편집: Jan 2017년 5월 17일
mean_sine = sum(sine) / length(deg);
% ^^^
The mean is the sum of the elements divided by the number of elements.
we are nor allowed builtin functions
This is nonsense. I know that teachers ask such questions, but:
a = b
calls the builtin function subsassgn already.
"deg" sounds like the input is in degrees. Then convert the values to radians at first.
Append semicolons to the lines to suppress the output and call your function like
[sine,mean_sine] = sindeg(deg)

Isaac DeVaughn
Isaac DeVaughn 2018년 1월 4일
I think what they were talking about with this question is that you can't use sind the function that allows for inputs of degrees which easily solves the question. I'm slightly confused by the 2nd line of you code because you don't actually take the sin of anything.
  댓글 수: 2
John D'Errico
John D'Errico 2018년 1월 4일
편집: John D'Errico 2018년 1월 4일
Please don't answer a question if you only have a comment. Hint: There are comments when you want to comment.
Jan
Jan 2018년 1월 4일
편집: Jan 2018년 1월 4일
@Isaac: Compare:
deg = 123.4;
rad = deg * pi / 180;
sin1 = (exp(1i*rad) - exp(-1i*rad)) / (2i)
sin2 = sin(rad)
exp(1i * x) = cos(x) + 1i * sin(x)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by