I have two approximated functions and I want to find the maximum value (error) between their graphs, to see how much they approach. I used : FindMaximum[Abs[f[x] - p[x]], x], but Mathematica 8 gave me that output: {2.75612*10^104, {x -> 2.75612*10^104}}

what does this mean? It is too big!

can you suggest me a better way?

Thanks

This is probably caused by some sort of overflow in one of the two functions when the input value of x is a very large number. You should restrict your domain to [-1, 1]:

```
FindMaximum[{Abs[f[x] - p[x]], -1 <= x <= 1}, x]
```

It's hard to tell not knowing your functions, but I'd guess that the position of the maximum it found is well outside your intended domain. You may have more success using a different form or `FindMaximum`

, namely

```
FindMaximum[Abs[f[x] - p[x]],{x,x0,xmin,xmax}]
```

where `x0`

would be your initial guess for it (can be any point inside the region of interest), and `xmin,xmax`

are the endpoints of your region of interest.

The reason is probably what Leonid said. To look at what FindMaximum is doing in real time, you can do

```
f[x_] := Sin[x];
p[x_] := x^2;
lst = {};
Monitor[
FindMaximum[Abs[f[x] - p[x]], x,
EvaluationMonitor :> (AppendTo[lst, x]; Pause[.01])
], ListPlot[lst, PlotRange -> Full]
]
```

the vertical axis on the resulting plot is the x-coordinate FindMaximum is currently looking at. Once FindMaximum is done, the plot disappears; the list is stored in lst so you can eg ListPlot it.

You can also try this with `{Abs[f[x] - p[x]], -1 <= x <= 1}`

as the argument, as suggested by Spencer Nelson, to see how the search proceeds then.

If you want to search for a global maximum within the interval {a, b}, I suggest NMaximize:

`NMaximize[{Abs[f[x] - p[x]], a <= x <= b}, x]`

.

Note that `FindMaximum`

searches for any *local* maximum, which is only good if you know that, for your particular function, a local maximum would also be a global maximum.

Instead of the objective function `Abs[f[x] - p[x]]`

, you may wish to use the objective function `(f[x] - p[x])^2`

. This would make the objective function smooth (if `f[x]`

and `p[x]`

are smooth), which can help improve the efficiency of some numerical optimization methods.

Similar Questions

I have two UITextfields. First UITextfield - Minimum value = 1 and maximum value = not fixed Second UITextfield - Minimum value = 0 and maximum value = 99 I tried using the following : - (BOOL)te

I have an array A=[a1,a2,a3,a4,a5...] and I want to find two elements of the array, say A[i] and A[j] such that i is less than j and A[j]-A[i] is minimal. Would this code do the job: def findMinDiffe

I have built two XML files that map the content of a given folder: <root> <folder name=C:\a\b permision=yes folderCount=1> <folders> <folder name=C:\a\b\c permision=yes

A previous question asked how to find to find the maximum value of an array in CUDA efficiently: Finding max value in CUDA, the top response provided a link to a NVIDIA presentation on optimizing redu

I have been using a tidy little routine that I found here to calculate the difference in days between two dates in AS3. I am getting some strange results and I am wondering if any of you inter-codal-m

Given two Mathematica sets of data such as data1 = {0, 1, 3, 4, 8, 9, 15, 6, 5, 2, 0}; data2 = {0, 1, 2, 5, 8, 7, 16, 5, 5, 2, 1}; how can I create a set giving me the maximum value of the two lists,

I'm pretty sure this is a duplicate, but I have tried everything, and I still cannot seem to get the differences. I have two lists of strings: listA and listB. I'm trying to find items in listA that a

How can I find difference between two time intervals. Like 13:45:26.836 - 14:24:18.473 which is of the format Hour:Min:Sec:Millisecs. Now i need to find the time difference between these two times.

I have two integer parameters a and b. And two integer variables max and min. I want to assign to max the maximum of a and b and to min the minimum of the two. I need to do this operation millions of

I'm reading more open source javascript frameworks and found more ways of how to create anonymous functions, but whats is different and best way? (function() { this.Lib = {}; }).call(this); (function(

I have a requirement. I have two tables say TableA and TableB. Both having a column called rec_id. My requirement is to get the maximum of the values contained in these two columns using a single qu

I am currently learning to use canvas, and do not understand the difference between these two functions. From what I have read, the translate method 'moves the canvas'? Can someone explain this? Edit:

Since the nonmember begin() and end() functions were added for standard contains in the C++11 revision, why have the nonmember versions of the rbegin() and rend() functions not been added as well? I f

I've got a matrix (n x m). And I'd like to know, for each row, the indexes of the coloums that contain the first two maximum values: 2 3 4 2 2 4 7 1 1 1 2 4 5 5 9 6 1 4 2 1 9 8 1 2 The answer should

I am trying to use std::atomic library. What's the difference between specialized and non-specialized atomic member functions? What's the difference (if there is any) between following functions? op

I have a website which has, amongst others, two pages: an event booking page and a login page. My goal: I want to declare two Ajax functions, loginUser() and bookEvent(), that I can use on any page, a

I'm using JFreeChart 1.0.14 and I want to get the domain value from maximum range value. I use a XYLineChart and for now I get the maximum of the range value with the following code: Number maximum =

Whats the diffrerence between Maximum Connection Reuse Time and Time-To-Live Connection Timeout in Oracle 11g (11.2) ?. I could not able to find the difference in Oracle documentation, Are they both s

I only found here how can I get the key of the maximum value: max(d, key=d.get()) but I need to search the maximum key and return the value of this key. thanks,

Is there a way to programmatically retrieve the maximum float value for php. Akin to FLT_MAX or std::numeric_limits< float >::max() in C / C++? I am using something like the following: $minimumC

So I wrote these two versions of the overloaded assignment operator for an ADT I wrote in class. When I use them in conjunction with my overloaded ostream << operator for that same ADT I see dif

I'm trying to write two template functions. They must simply return reference to local variable. But it doesn't work: class Cube_cache_value { public: //... template<> QVector<unsigned short&

How do I write a query to find the Nth maximum value in MySQL?

I want to find out the maximum value of the each key in the array $arr1= array( 0=>array(1,2,3), 1=>array(2,4,6), 2=>array(25,4,5)); } I want to find the maximum value for each value for the

I have a database field know as SCORES which has Scores the value may be like the following 123 14 56* 342 423* I am storing that in a Varchar Field in the database. Suppose If I convert that to a int

I want to select two consecutive records by date, records from the database, with a maximum difference in consecutive dates. there is a table name date abc 1242 bcd 1246 bsd 1247 bse 1249 The result

I’m looking to get the max discrepancy between two tables per day, per id. I have the following data in a mysql database insert into test.foo values ('2010-01-10', 1, 10); insert into test.foo values

Given an array of N integers, sort the array, and find the 2 consecutive numbers in the sorted array with the maximum difference. Example – on input [1,7,3,2] output 4 (the sorted array is [1,2,3,7],

I came across this video which is discussing how most recursive functions can be written with for loops but when I thought about it, I couldn't see the logical difference between the two. I found this

I want to find maximum value in each column for every 2 rows (say). How to do that in R? For example matrix(c(3,1,20,5,4,12,6,2,9,7,8,7), byrow=T, ncol=3) I want the output like this matrix(c(5,4,20,

On page three of this OpenCL reference sheet there are two built in vector length functions with identical parameters: length() and half_length(). What is the difference between these functions? I gat

I'm asked to write a function which finds the maximum alternating sum of digits in a given number and a given number of digits. For example, the number 81010 has 3 alternating sum with length 3 - (8-1

Consider this code snippet and try to guess what y1 and y2 evaluate to static class Extensions { public static Func<T> AsDelegate<T>(this T value) { return () => value; } } class Progra

If i have two stacks, which i have to put elements that come from an array, and i have to find a recursive way to put elements that obey the rule of finding the lesser difference between the sum of th

I have these 2 dicts: a={test1:90, test2:45, test3:67, test4:74} b={test1:32, test2:45, test3:82, test4:100} how to extract the maximum value for the same key to get new dict as this

I have two matrixes A = array([[ 12., 0.],[ 0., 4.]]) B = array([[ 13., 5.],[ -1., -5.]]) and I want to get a third one whose elements correspond to the maximum of the previous matrixes. For instance

Given a numeric secondary index in Riak I can do range queries, like: Find me all values* with index sn between 1 and 10. Is there a way to find the maximum value for a numeric index? I.e. Fin

I have been using minMaxLoc to compute the maximum value of the data obtained by running a laplacian filter over a grayscale image. My simple intention is to roughly estimate the sharpness. I encounte

Define an item as having: a unique id a value a creation time a deletion time I have two input streams - one that informs me when an item is created, one that informs me when the item is deleted. Ca

I have two JSpinner one is for minimum and another one for maximum value set. I just want that if min is set some value then user can not enter less than minimum text field value in JSpinner of maximu

I am trying to find the maximum pixel value of a cv::Mat. The Problem : *maxValue is always returning 0. From this S.O. thread, I understand that 'max_element return iterators, not values. This is why

Possible Duplicate: Performance difference between functions and pattern matching in Mathematica I often find a heavy use of pure functions in a lot of the answers posted here, and often those solut

Does any C++ GUI toolkit out there support definition of callback functions as C++11 lambda expressions? I believe this is a unique pro of using C# (compared to C++ at least) for writing GUI-based pro

I have a question may be easy(I'm new to hadoop) I want to make a mapping on big dataset, and the mapping process depends on the maximum value. for example Input: (key) (value) --------------------- k

I'm wondering what the difference between the functions QList::length() and QList::count() really is. The docs say: int QList::length() const This function is identical to count(). int QList::count(

What is the maximum value allowed for tinyint(2)? Is the maximum above allowed value 255 or 99 ? I am confused because (2) after tinyint(2) denotes only the display... Am I correct?

I am calculating the difference between two times and i am able to get the difference in hours and minuted using separate equations,is there any single equation from which i can get hours and minutes

What is the difference between functions in math and functions in programming?

Given a table like this, what query will the most recent calibration information for each monitor? In other words, I want to find the maximum date value for each of the monitors. Oracle-specific funct

I've this tuple: lpfData = ((0.0, 0.0), (0.100000001490116, 0.0879716649651527), ..., (1.41875004768372, 0.481221735477448),..., (45.1781234741211, 0.11620718985796)) and I want to find the maximum v