필터 지우기
필터 지우기

writting down the code for the function

조회 수: 1 (최근 30일)
Bijaya
Bijaya 2024년 2월 7일
댓글: Walter Roberson 2024년 2월 8일
Attached file has the function and here is my matlab code pasted below
function y = myFunction(x, n)
if n == 1
y = 4 * sin(x) / (25*x + sin(25));
else
y = 2 * tan(5*n) / bi;
end
end
% Define the values of x and n
n = 2;
% Call the function to calculate y
y = myFunction(x, n);
% Display the result
disp(y);

답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 7일
y = 4 * sin(x) / (25*x + sin(25));
That is not vectorized. It needs to be
y = 4 * sin(x) ./ (25*x + sin(25));
Also remember that the parameters to the trig functions are in radians . If you want degrees, use sind
  댓글 수: 9
Bijaya
Bijaya 2024년 2월 8일
The above modified one leads to following errors
Error using num2str
Input to num2str must be numeric.
Error in untitled523 (line 26)
disp(['Value of Bi:', num2str(Bi_value)]);
Walter Roberson
Walter Roberson 2024년 2월 8일
Bi_value is symbolic, not numeric. You cannot num2str() it. You can char() it.

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

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by