How do I make my symbolic function into a matrix?

2 Ansichten (letzte 30 Tage)
Heather G
Heather G am 4 Dez. 2015
Kommentiert: Heather G am 8 Dez. 2015
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Dez. 2015
[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 Kommentare
Walter Roberson
Walter Roberson am 7 Dez. 2015
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.
Heather G
Heather G am 8 Dez. 2015
Thank you so much for answering my questions!
Everything looks great now :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by