Prev: Displaying Only Last Positive Value
Next: mex error
From: Leyen on 29 Jul 2010 14:59 Hi I have 2 functions that are very complicated functions of x and T. I produced some data and used TriScatteredInterp to generate 2 functions F1 and F2 for each function. Now I would like to find x and T such that F1(x,T)=A and F2(x,T)=B for a given [A,B]. Since F1 and F2 are not explicit functions I can't directly use the "solve" command. Does anyone know a good way to go about determining the solutions x and T? Thanks.
From: Walter Roberson on 29 Jul 2010 15:10 Leyen wrote: > Hi I have 2 functions that are very complicated functions of x and T. I > produced some data and used TriScatteredInterp to generate 2 functions > F1 and F2 for each function. > > Now I would like to find x and T such that F1(x,T)=A and F2(x,T)=B for a > given [A,B]. Since F1 and F2 are not explicit functions I can't > directly use the "solve" command. Does anyone know a good way to go > about determining the solutions x and T? Thanks. It appears to me that you should be able to use FMINSEARCH for that. You would be attempting to minimize (F1(x,T)-A).^2 or (F1(x,T)-B).^2 . I use the square here rather than the absolute value so that the first derivative is continuous, as is required by most minimizers.
From: Leyen on 29 Jul 2010 18:05 Walter Roberson <roberson(a)hushmail.com> wrote in message <i2sjv3$4hl$1(a)canopus.cc.umanitoba.ca>... > Leyen wrote: > > Hi I have 2 functions that are very complicated functions of x and T. I > > produced some data and used TriScatteredInterp to generate 2 functions > > F1 and F2 for each function. > > > > Now I would like to find x and T such that F1(x,T)=A and F2(x,T)=B for a > > given [A,B]. Since F1 and F2 are not explicit functions I can't > > directly use the "solve" command. Does anyone know a good way to go > > about determining the solutions x and T? Thanks. > > It appears to me that you should be able to use FMINSEARCH for that. You would > be attempting to minimize (F1(x,T)-A).^2 or (F1(x,T)-B).^2 . I use the square > here rather than the absolute value so that the first derivative is > continuous, as is required by most minimizers. I get this error when using fminsearch: Undefined function or method 'F1' for input arguments of type 'double'. Error in ==> WMSiteratexT>myfun1 at 64 F1a=F1(a(1),a(2)).^2-0.31734; Error in ==> fminsearch at 205 fv(:,1) = funfcn(x,varargin{:}); Error in ==> WMSiteratexT at 60 solx= fminsearch(@myfun1, [x0, y0]); Does fminsearch have a problem with using the function generated by triscatteredinterp? I tried inputting the start guess [x0,T0] into F1 and it works fine.
From: Walter Roberson on 29 Jul 2010 18:47 Leyen wrote: > I get this error when using fminsearch: > > Undefined function or method 'F1' for input arguments of type 'double'. > > Error in ==> WMSiteratexT>myfun1 at 64 > F1a=F1(a(1),a(2)).^2-0.31734; > > Error in ==> fminsearch at 205 > fv(:,1) = funfcn(x,varargin{:}); > > Error in ==> WMSiteratexT at 60 > solx= fminsearch(@myfun1, [x0, y0]); > > Does fminsearch have a problem with using the function generated by > triscatteredinterp? No, but F1 and F2 would have to be in scope in myfun1. As you did not use an anonymous function, your myfun1 would have to access F1 and F2 by way of global variables or nested variables or a similar technique. I notice that you are doing the equivalent of F1(x,T).^2 - A . That is not correct for minimization, as it is going to search for F1(x,T) nearest to 0. It needs to be (F1(x,T) - A).^2 so that it will search for F1(x,T) nearest to A .
From: Leyen on 29 Jul 2010 21:17 Thanks. I now have the two fminsearch commands working separately, i.e. i can find the x,T that minimize F1 and the x,T that minimize F2. There are many values of x,T that satisfy this, depending on the initial value. What I really want is the x,T that minimize both F1 and F2 simultaneously. Any ideas on this? Thanks again. Walter Roberson <roberson(a)hushmail.com> wrote in message <i2t0mf$ngn$1(a)canopus.cc.umanitoba.ca>... > Leyen wrote: > > > I get this error when using fminsearch: > > > > Undefined function or method 'F1' for input arguments of type 'double'. > > > > Error in ==> WMSiteratexT>myfun1 at 64 > > F1a=F1(a(1),a(2)).^2-0.31734; > > > > Error in ==> fminsearch at 205 > > fv(:,1) = funfcn(x,varargin{:}); > > > > Error in ==> WMSiteratexT at 60 > > solx= fminsearch(@myfun1, [x0, y0]); > > > > Does fminsearch have a problem with using the function generated by > > triscatteredinterp? > > No, but F1 and F2 would have to be in scope in myfun1. As you did not use an > anonymous function, your myfun1 would have to access F1 and F2 by way of > global variables or nested variables or a similar technique. > > I notice that you are doing the equivalent of F1(x,T).^2 - A . That is not > correct for minimization, as it is going to search for F1(x,T) nearest to 0. > It needs to be (F1(x,T) - A).^2 so that it will search for F1(x,T) nearest to A .
|
Pages: 1 Prev: Displaying Only Last Positive Value Next: mex error |