how do i write this equation in live script

조회 수: 8 (최근 30일)
mark@4882
mark@4882 2020년 1월 21일
편집: Image Analyst 2020년 1월 22일
Create a function handle called f which takes a single input variable and performs the following calculation.
f(θ) = sin3(θ) 2 + cos(θ) sin(2θ)
The function should be “vectorized” with element-wise operators, where appropriate, so that it can take single numbers as input or matrices as input.

답변 (1개)

Image Analyst
Image Analyst 2020년 1월 21일
What does sin3(θ) 2 mean? Tell us in words because there is no sin3() function.
Try
theta = linspace(-pi, pi, 1000);
f = sin(theta).^3 + cos(theta) .* sin(2*theta);
Adapt as needed after you figure out what that weird equation means.
  댓글 수: 6
mark@4882
mark@4882 2020년 1월 22일
f('\theta') = @('\theta) (sin('/theta').^3)./(2 + cos('/theta') sin(2.*'\theta'))
I'm still getting an error
Walter Roberson
Walter Roberson 2020년 1월 22일
편집: Image Analyst 2020년 1월 22일
You cannot use \theta or '\theta' as the name of a variable.
f = @(theta) (sin(theta).^3)./(2 + cos(theta) .* sin(2.*theta))
However you appear to have forgotten that MATLAB does not have any implicit multiplication. If you want to multiply two values you must use either the * or .* operation. The * operation is for algebraic matrix multiplication ("inner product") and the .* operation is for element-by-element multiplication.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by