Creating a general function handle


by mikeph
Tags: creating, function, handle
mikeph
mikeph is online now
#1
Aug9-11, 09:04 AM
P: 1,199
I'm writing a MATLAB function m-file which has input argument of some N-by-1 vector.

Say this vector is [1,2,3].

I want to create a function handle representing a sum of x taken to the power of each number that appears in the vector, so in this case it is:

f = @(x) [x^1 + x^2 + x^3]; (x scalar)

The point is, I don't know how to define f when I don't explicitly know what the input vector is. Can anyone help me generate a general function handle? The trick is because N is variable.
Phys.Org News Partner Science news on Phys.org
NASA's space station Robonaut finally getting legs
Free the seed: OSSI nurtures growing plants without patent barriers
Going nuts? Turkey looks to pistachios to heat new eco-city
uart
uart is offline
#2
Aug9-11, 02:32 PM
Sci Advisor
P: 2,751
v=[1,2,3]

f = @(x) sum(x.^v)
mikeph
mikeph is online now
#3
Aug10-11, 03:18 AM
P: 1,199
I like it! Thanks very much


Register to reply

Related Discussions
Need help Creating Rational function Calculus 0
Matlab help, function handle Engineering, Comp Sci, & Technology Homework 0
How to handle the Dirac delta function as a boundary condition Differential Equations 5
Can general prototyping boards handle up to 4-5A in current? Electrical Engineering 1
Creating a Function-Derivatives Calculus 1