Home > other >  Questions about MATLAB nested anonymous functions
Questions about MATLAB nested anonymous functions

Time:09-30

I set up a nested anonymous functions,
> Myffhd=@ (a) (quad (@ (x) + x (a), 1, 2))
View, from the result of operation of x value is "1, 2" on the average, and seems to have to enter two or more constants, the x value of the average of the top two, for these constant (below)
> Myffhd=@ (a) (quad (@ (x) + x (a), 1, 2, 3))


But if only a constant input (below), will go wrong when the anonymous function called
@ (a) (quad (@ (x) + x (a), 1))

Error:
> Myffhd (5)
The number of input parameters,

Error quad (line 60)
If ~ isscalar (a) | | ~ isscalar (b)

Wrong @ (a) (quad (@ (x) + x (a), 1))

Why is this?

CodePudding user response:

The top one, want some help

CodePudding user response:

Quad (fun, a, b)
Try to use the MATLAB function recursive adaptive Simpson integral method to calculate the function fun approximate integral from a to b, the error is less than 1 e - 6, fun is the function handle, the scope of a and b must be limited and function y=fun (x) should accept vector parameter x y and returns the vector results, namely is calculated at each element of x integrand,
  • Related