MATLAB: Using fsolve when the function handle takes in 2 variables that are both vectors

fsolve

I'm trying to solve system of non-linear equations. My function handle fun takes in 2 variables ( x and y) that are both vectors.Each vector has 2 components. I want fsolve to return me 2 vectors with 2 components each. However, fsolve can only return one vector. How do I find an appropriate solution for my problem? Any help appreciated.
fun=@(x,y) [exp(-exp(-(x+y))) - x.*(1+x.^2); x.*cos(y) + y.*sin(x) - [0.5;0.5]];
x0=[1;1]; % initial guess for x vector
y0=[0;1]; % initial guess for y vector
[result1,result2]=fsolve(fun,x0,y0);

Best Answer

Recast as 4-vector w/ v(1:2) -- x; v(3:4) -- y:
fun2=@(x) [exp(-exp(-(x(1:2)+x(3:4)))) - x(1:2).*(1+x(1:2).^2); ...
x(1:2).*cos(x(3:4)) + x(3:4).*sin(x(1:2)) - [0.5;0.5]];
>> fsolve(fun2,[x0;,y0])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
0.4627
0.4627
0.0876
0.0876
>> fun2(ans)
ans =
1.0e-11 *
-0.2900
-0.0679
-0.7623
-0.0910
>>