tailieunhanh - CRC.Press A Guide to MATLAB Object Oriented Programming May.2007 Episode 2 Part 9

Tham khảo tài liệu ' a guide to matlab object oriented programming episode 2 part 9', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 334 A Guide to MATLAB Object-Oriented Programming 8 x repmat x 1 size coef 2 9 varargout reshape sum coef . x. power 2 size 1 The polynomial function evaluation takes place in line 9. The equation for the right-hand expression can be written as V. . C C x C x2 C x3. . C 7xN. 1 yi j C1 C2 xi j C3 xi j C 4 xij CNxi j w N LLC-S1 The other lines check inputs copy values reshape matrices and allow the expression on line 9 to be written in vectorized form. Line 2 checks the number of inputs against the number supported by the functor. The first check numel index 1 throws an error if the function call includes index operators beyond the initial . This check is usually acceptable. The second check numel 1 limits the number of input arguments to 1. In general functors can accept any number of arguments and numel serves the same purpose as nargin. Line 5 reshapes the input argument as a column. Line 6 duplicates the vector of coefficients one row for every element in the column of x. Line 7 performs the same duplication for the array of powers. Line 8 repeats the column of x values one column for every column in coef. The local variables x coef and power are now the same size. Line 9 uses element-by-element operators to produce a value for every input and then resizes the result to match the input size. Functor Handles Now that we have something that behaves a lot like a function it is natural to wonder where appearances give way to reality. For example you can t use the @ character to create a function handle to the functor function. The commands p cPolyFun p_func @p result in an error because MATLAB will not allow p to be both a variable and a function. By this point in our object-oriented odyssey you might look at the second command above and wonder whether you can overload the @ operator and return the correct handle. Sadly as far as I have been able to determine you can t overload the @ operator. Anonymous functions provide a .

TỪ KHÓA LIÊN QUAN