How do I make my symbolic function into a matrix?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Heather G
il 4 Dic 2015
Commentato: Heather G
il 8 Dic 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.
0 Commenti
Risposta accettata
Walter Roberson
il 5 Dic 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 Commenti
Walter Roberson
il 7 Dic 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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!