File: freemat_feval.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (75 lines) | stat: -rw-r--r-- 1,662 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
<TITLE>FEVAL Evaluate a Function
</TITLE>
</HEAD>
<BODY>
<H2>FEVAL Evaluate a Function
</H2>
<P>
Section: <A HREF=sec_freemat.html> FreeMat Functions </A>
<H3>Usage</H3>
The <code>feval</code> function executes a function using its name.
The syntax of <code>feval</code> is
<PRE>
  [y1,y2,...,yn] = feval(f,x1,x2,...,xm)
</PRE>
<P>
where <code>f</code> is the name of the function to evaluate, and
<code>xi</code> are the arguments to the function, and <code>yi</code> are the
return values.

Alternately, <code>f</code> can be a function handle to a function
(see the section on <code>function handles</code> for more information).

Finally, FreeMat also supports <code>f</code> being a user defined class
in which case it will atttempt to invoke the <code>subsref</code> method
of the class.
<H3>Example</H3>
Here is an example of using <code>feval</code> to call the <code>cos</code> 
function indirectly.
<PRE>
--&gt; feval('cos',pi/4)

ans = 
    0.7071 
</PRE>
<P>
Now, we call it through a function handle
<PRE>
--&gt; c = @cos

c = 
 @cos
--&gt; feval(c,pi/4)

ans = 
    0.7071 
</PRE>
<P>
Here we construct an inline object (which is a user-defined class)
and use <code>feval</code> to call it
<PRE>
--&gt; afunc = inline('cos(t)+sin(t)','t')

afunc = 
  inline function object
  f(t) = cos(t)+sin(t)
--&gt; feval(afunc,pi)

ans = 
   -1.0000 

--&gt; afunc(pi)

ans = 
   -1.0000 
</PRE>
<P>
In both cases, (the <code>feval</code> call and the direct invokation), FreeMat
calls the <code>subsref</code> method of the class, which computes the requested 
function.
</BODY>
</HTML>