How do I make my symbolic function into a matrix?

I have the following function:
Grow= 1/(15.69892467*(2*3.14159).^.5)*(2.82718).^(-(.5*((y-(.879*x+5.682))/15.69892467).^2))
where I defined x and y using syms x y
The graph represents the growth kernel of an integral projection model for a grass species. I can graph it just fine using mesh(x,y,Grow, [1, 500]) but now I need to make a matrix of the data so that I can find the eigenvalues and eigenvectors.
I want the matrix to be a square matrix that represents the different combination of x and y values. So row one would be the solution to the equation when y=1 and x = 1, 2,...to 500 and row 2 would be y=2, x=1,2... to 500 etc. I'd like to make a 500 by 500 matrix.
I would appreciate any advice you can give me. I have the feeling this should be a simple operation but I can't figure it out. I tried making two vectors x and y but because of the nature of matrix subtraction, I just ended up with another vector.

 Accepted Answer

[x, y] = ndgrid(1:500,1:500);
Grow = 1/(15.69892467*sqrt(2*pi)) * (2.82718).^(-(.5*((y-(0.879*x+5.682))/15.69892467).^2));
Note: rank(Grow) says 79... and I suspect that the greatest part of it is numeric nonsense)

3 Comments

Thank you, that seems to work for that specific equation, but I am coming across a problem when I implement this strategy with the other half of my equation. I have the equation:
Fec1=(0.1485*log(x)+ 0.0643)*(((61.8411*y-855.048)*(1-.017))).^(-.33)*(0.14348*(2.72818).^(-0.0646743*(-3.07+1).^2)) When I graph it with the symbolic variables, I get this graph:
However, once I convert it to a matrix it becomes a complex double, which I can't graph normally. You have definitely solved my initial problem, but do you have any suggestions for what to do now?
I have tried graphing Rep=real(Fec1) but that seems to scale the graph strangely while maintaining the same shape.
When you plot using symbolic variables, the portion of the plot that is complex is silently omitted.
Your Fec1 is complex when 61.8411*y-855.048 is negative. The boundary for that is y = 13.8265328398104 at which point you have a division by 0, so it approaches infinity from above y = 13.8265328398104 . You should therefore only plot at values above that for y.
Your Fec1 has log(0) at x = 0 which leads to negative infinity near x = 0. It is negative below x = 1/exp(643/1485) which is about 0.6485 . You should avoid plotting for x <= 0 but you can get close to 0 if you want.
You made a small transcription error when you converted to MATLAB from symbolic. You have
Fec1=(0.1485*log(x)+ 0.0643)*(((61.8411*y-855.048)*(1-.017))).^(-.33)*(0.14348*(2.72818).^(-0.0646743*(-3.07+1).^2));
but you need
Fec1=(0.1485*log(x)+ 0.0643).*(((61.8411*y-855.048)*(1-.017))).^(-.33)*(0.14348*(2.72818).^(-0.0646743*(-3.07+1).^2));
which is to say you need .* instead of * between the x and the y parts.
If you put the two together and use (for example)
[x,y] = ndgrid(linspace(1/10,500), linspace(13.9, 500));
Fec1=(0.1485*log(x)+ 0.0643).*(((61.8411*y-855.048)*(1-.017))).^(-.33)*(0.14348*(2.72818).^(-0.0646743*(-3.07+1).^2));
surf(x, y, Fec1, 'edgecolor', 'none')
then you will get a reasonable plot.
Thank you so much for answering my questions!
Everything looks great now :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!