In matlab, we use meshgrid
instead of a double for-loop to increase the speed, especially when the number of iterations is large.
In my application, I am using meshgrid
to find the critical point of a matrix.
syms x
a=0.1:5
b=0.1:5
[A,B]=meshgrid(a,b)
y=A*x^2+B*x+B
y_deriv=diff(y,x)
solution=solve(y_deriv==0,x)
However, it gives me
Warning: 25 equations in 1 variables.
> In C:\Program Files\MATLAB\R2013b\toolbox\symbolic\symbolic\symengine.p>symengine at 56
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 170
Warning: Explicit solution could not be found.
> In solve at 179
solution =
[ empty sym ]
What I meant to do is:
solve(y_deriv(1)==0,x)
and
solve(y_deriv(2)==0,x)
... and so on.
I could do it in a loop, but I don't want to. Is there any element-by-element wise solving operation in matlab?
Update:
I think y_deriv
gives me:
[ x/5 + 1/10, (11*x)/5 + 1/10, (21*x)/5 + 1/10, (31*x)/5 + 1/10, (41*x)/5 + 1/10]
[ x/5 + 11/10, (11*x)/5 + 11/10, (21*x)/5 + 11/10, (31*x)/5 + 11/10, (41*x)/5 + 11/10]
[ x/5 + 21/10, (11*x)/5 + 21/10, (21*x)/5 + 21/10, (31*x)/5 + 21/10, (41*x)/5 + 21/10]
[ x/5 + 31/10, (11*x)/5 + 31/10, (21*x)/5 + 31/10, (31*x)/5 + 31/10, (41*x)/5 + 31/10]
[ x/5 + 41/10, (11*x)/5 + 41/10, (21*x)/5 + 41/10, (31*x)/5 + 41/10, (41*x)/5 + 41/10]
What I want is to solve x/5+1/10==0
, x/5+11/10==0
, x/5+21/10==0
, ... and so on for all elements in the matrix.