From: Mark on
Hi everyone,
Is there a way to evaluate vector functions in Matlab? Eg where x = [x1;x2;x3], F(x) = [sin(x1) + 3*x2; x1^2 + x2^2 - x3; cos(x3)]
Can I calculate F(x0) for some initial guess vector and use this in an iterative formula?
Apparently it's not possible to make inline vector functions, is there another method?

Many thanks
Mark
From: Walter Roberson on
Mark wrote:

> Is there a way to evaluate vector functions in Matlab? Eg where x =
> [x1;x2;x3], F(x) = [sin(x1) + 3*x2; x1^2 + x2^2 - x3; cos(x3)]
> Can I calculate F(x0) for some initial guess vector and use this in an
> iterative formula?
> Apparently it's not possible to make inline vector functions, is there
> another method?

I don't see any difficulty...

F = @(x) [sin(x(1))+3*x(2); x(1).^2+x(2).^2 - x(3); cos(x(3))];

>> F([.2,.5,.9])
ans =
1.69866933079506
-0.61
0.621609968270664

>> G = inline('[sin(x(1))+3*x(2); x(1).^2+x(2).^2 - x(3); cos(x(3))]')
G =
Inline function:
G(x) = [sin(x(1))+3*x(2); x(1).^2+x(2).^2 - x(3); cos(x(3))]
>> G([.2,.5,.9])
ans =
1.69866933079506
-0.61
0.621609968270664
 | 
Pages: 1
Prev: white pixel
Next: Hidden Markov Model