how do i write this equation in live script
Mostrar comentarios más antiguos
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.
Respuestas (1)
Image Analyst
el 21 de En. de 2020
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 comentarios
mark@4882
el 21 de En. de 2020
Walter Roberson
el 21 de En. de 2020
is sin(2.*theta)
Image Analyst
el 21 de En. de 2020
Manav, with the divide symbol (slash) and using additional parentheses, you should be able to figure this homework out on your own.
Walter Roberson
el 21 de En. de 2020
./ and .* for vectorized form
mark@4882
el 22 de En. de 2020
Walter Roberson
el 22 de En. de 2020
Editada: Image Analyst
el 22 de En. de 2020
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.
Categorías
Más información sobre Equation Solving en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!