How do I turn a symbolic function into a matrix?
Show older comments
I'm trying to multiply multiple symbolic equations together to create an equation (NFKernel) and then turn that equation into a 100 by 100 matrix.
The reason is that the math is much easier when not in matrix form, plus I need the matrix entries later for eigenvalue work. I know that if I could write out the equation for NFKernel and then use ngrid I can easily turn the equation into a matrix. The problem is that creating this large equation (NFKernel), I'm not sure how to make Matlab recall the parts of the equation so that I can turn it into a matrix. What I want is something where I run the script using symbolic variables up until the end of the command, where there would be some sort of "recall that NFKernel = this bugger" and then use ngrid (or something similar) to make my matrix.
Does anyone have any idea how to do this? I've tried:
syms f(x,y);
f(x,y) = NFKernel
[x,y] = ndgrid(linspace(1/10,500), linspace(1/10, 500))
subs (f(x,y))
NFKernel = double(ans)
but my computer, or the program, I'm not sure which, goes so slowly it can never finish.
Here's the exact problem:
syms x y
NFSurv = .0723*log(x)+.6829
NFGrowrate = 0.646598*x+4.7886;
NFGrowstdv = 4.747;
NFGrow = (1/(NFGrowstdv*((2*pi).^(0.5))))*(2.7182818).^(-(0.5*(((y-NFGrowrate)/NFGrowstdv).^(2))))
NFP= NFGrow*NFSurv
NFbz = ((1-0.0338)*(0.06238*y-0.51856)).^(-0.33);
NFPbz = 0.881*log(x)+0.374;
newseed = 2;
NFC0 = (1/(2*pi*2.21).^(0.5))*(2.7182818).^(-0.5*(((newseed-2.480)/2.21).^(2)));
NFFec= NFPbz*NFbz*NFC0
NFKernel = NFP+NFFec
I need NFKernel as a 100 by 100 matrix.
Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!