Using the symbolic toolbox is often a mistake that people do, just because they think because the value of some parameters is not currently known, then they MUST be symbolic. It seems a logical conclusion. But it is not true. When you create/write a function of some parameters, you need not in advance know exactly what values those paramters will take on.
You have some function, with unknown parameters.
Exyt = @(x,y,t) [2.^x - y;y - sin(t)];
It exists. It is definable, and usable. If you know the value of those parameters, you can evaluate those expressions. And if you know the value of SOME of them, you can fix them at some point in time. Thus:
Exyt(1,2,3)
ans =
0
1.8589
We can now create a new function handle, fixing t at any value we desire.
Exy = @(x,y) Exyt(x,y,pi/4)
Exy =
function_handle with value:
@(x,y)Exyt(x,y,pi/4)
Exy(2,3)
ans =
1
2.2929
It can be passed around, used by tools such as fsolve.
[xy,fval,exitflag] = fsolve(@(xy) Exy(xy(1),xy(2)),[1 1])
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
xy =
-0.5 0.70711
fval =
2.3215e-12
0
exitflag =
1
So for t = pi/4, the solution is as given. Nothing ever needed to be declared as symbolic at any point in time.
In fact, we can even get fancy. Suppose we wanted to know the solution in terms of x and y, as an implicit function of t? NOT A PROBLEM. We will return to Exyt for this.
opts = optimset('fsolve');
opts.Display = 'none';
xyoft = @(t) fsolve(@(xy) Exyt(xy(1),xy(2),t),[1 1],opts);
xyoft(pi/3)
ans =
-0.20752 0.86603
xyoft(pi/4)
ans =
-0.5 0.70711
Again, nothing symbolic ever passed through my fingers. There was never any need for that to happen.
I could also have varied t in a loop, creating a new function handle on the fly as I needed it, each time with that value of t embedded inside of it, much as I created xyoft.
COULD I have used the symbolic toolbox? Of course. It would be slower. A more inefficient use of CPU cycles. But if the plan is to use fsolve anyway, then why would I do so? Just because you have a hammer, this should not make every problem look like a nail.