Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]() ![]() In the early 1990s, to avoid eval and all of its quirks (if you don't know about this, DON'T look it up - it's totally discouraged), we recommended using feval for evaluating functions that might not be known until supplied by the user running the code. We used this, for example, for evaluating numeric integrals. We wanted to leave the integrand completely flexible and up to the user. Yet the integrator had to be able to evaluate the user function, an unknown at the time of creating the integrator.function I=integ(fcn,fmin,fmax,tol)if ~ischar(fcn) error(...)end% figure out some initial points to evaluatepts = linspace(fmin, fmax, 20);fv = feval(fcn,pts);I = ...:endThis had the advantage of not asking MATLAB to "poof" any variables into the workspace. It helped also avoid situations where there was a possibility of a function and variable having the same name, thereby possibly not giving you the version of ...read more >> More... |
![]() |
![]() |