How to write a function of x in a function?
4 次查看(过去 30 天)
显示 更早的评论
Im just getting started in Matlab and I cant figure this out
I want to write a function of x and then the value of x inside a function
For example a = Evaluate((x^2)+1, 2)
And I want it to give me the answer. Which should be 5.
function [a] = Evaluate(f(x),x)
end
Thanks!
0 个评论
采纳的回答
Walter Roberson
2020-3-8
function a = Evaluate(f, x)
a = f(x);
end
Which might be called like
Evaluate(@(x) (x^2)+1, 2)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!