I want to write a function that returns the value of f(y)
for any value of y
:
f(y) =tan( sin(y) - sin(tan(y)) )
How can I write this as a function in MATLAB?
Here is an example function for your purpose
function y = f(x)
y = tan(sin(x)-sin(tan(x)));
end
You could use an anonymous function, as elluded to in the comments by obchardon :
f = @(y) tan(sin(y) - sin(tan(y)))
% usage like any other function:
f(1)
Note that you do not include the (y)
on the left hand side of the =
, this syntax is reserved for indexing into variables , or symbolic math .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.