feval for beginner, evaluating a function at a specific fvalue
1 次查看(过去 30 天)
显示 更早的评论
how do I evaluate the following function at 55/8, 9/2? I keep getting feval errors saying I need a string or handle. Any help?
>> c
c =
55/8
9/2
>> f
f =
- 4*q1^2 + 55*q1 - 15*q2^2 + 135*q2 - 100
>> y=feval(f,c)
Error using feval
Argument must contain a string or function_handle.
0 个评论
采纳的回答
Star Strider
2015-4-15
The easiest way is to simply create an anonymous function out of ‘f’ and a vector out of ‘c’:
f = @(q) - 4*q(1)^2 + 55*q(1) - 15*q(2).^2 + 135*q(2) - 100;
c = [55/8; 9/2];
fc = f(c)
produces:
fc =
392.8125
0 个评论
更多回答(1 个)
Adam
2015-4-15
f should be a function handle or the name of an actual function, not a string containing a raw function. Just convert your function to a function handle e.g.
f = @(q1,q2) - 4*q1^2 + 55*q1 - 15*q2^2 + 135*q2 - 100
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!