Using fsolve with gpuArray
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a system of 5 non-linear equations I am trying to solve using fsolve. I'm calling fsolve many times for a bunch of different combinations of initial guesses for each of the 5 variables to see which one produces the most accurate result. I have defined the following initial guess vectors for each variable I am soliving for:
a = gpuArray([a1 a2 ... aN]);
b = gpuArray([b1 b2 ... bN]);
c = gpuArray([c1 c2 ... cN]);
d = gpuArray([d1 d2 ... dN]);
e = gpuArray( [e1 e2 ... eN]);
I then created a grid of initial guesses to solve over:
[aa,bb,cc,dd,ee] = ndgrid(a,b,c,d,e);
Finnally I used arrayfun to compute fsolve over this grid. The function max_Jemit(x, n0, kTe_eV, Vc) is the function containing my 5 equations:
[Solutionsx, Solutions_Val] = arrayfun(@(x01,x02,x03,x04,x05) fsolve(@(x) max_Jemit(x, n0, kTe_eV, Vc), [x01 x02 x03 x04 x05], opts), aa, bb, cc, dd, ee);
I get the following error:
Creating anonymous functions is not supported.
I am assuming it's referring to the line @(x01,x02,x03,x04,x05). However, that seems necessary to keep in so arrayfun knows where to put those arrays. This code works just fine using normal arrays (provided I include 'UniformOut', false). Is there a workaround for this?
0 commentaires
Réponses (1)
Kartik
le 21 Mar 2023
Hi,
It seems that the error message you are getting is related to the fact that anonymous functions are not supported in GPU arrays.
One possible workaround is to use a loop to call 'fsolve' for each initial guess combination, instead of using 'arrayfun'. This may not be as fast as using 'arrayfun', but it should still work.
0 commentaires
Voir également
Catégories
En savoir plus sur GPU Computing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!