Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Approximating (a+x)^0.5 using specific set of f...' topicStudent Support Forum > General > Archives > "Approximating (a+x)^0.5 using specific set of f..."

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
04/23/13 1:46pm

If you can know what the value of a is then minimize the squared error over the interval.

In[1]:= Clear[c1, c2, c3, c4, a, x];
a = 3/4;
{c1, c2, c3, c4} = {c1, c2, c3, c4} /. NMinimize[ Integrate[(Sqrt[a + x] - (c1*Sqrt[x] + c2*1 + c3*x + c4*x^2))^2, {x, 0, 1}], {c1, c2, c3, c4}][[2]];
Print[{c1, c2, c3, c4}];
Show[{
ListPlot[Table[{x, Sqrt[a + x]}, {x, 0, 1, 1/20}]],
Plot[c1*Sqrt[x]+c2*1+c3*x+c4*x^2, {x, 0, 1}]}]

During evaluation of In[4]:= {0.0324455,0.86275,0.501943,-0.0750298}

Out[5]= ...PlotSnipped...

If you can't know the values of a or x then minimize the squared error over a random sample.

In[6]:= Clear[c1, c2, c3, c4, a, x];
data = Table[
a = RandomReal[{0, 1}];
x = RandomReal[{0, 1}];
{x, Sqrt[a + x]}, {100}];
{c1, c2, c3, c4} = {c1, c2, c3, c4} /. NMinimize[ Total[Map[(#[[2]] - (c1*Sqrt[#[[1]]] + c2*1 + c3*#[[1]] + c4*#[[1]]^2))^2 &, data]], {c1, c2, c3, c4}][[2]];
Print[{c1, c2, c3, c4}];
Show[{
ListPlot[data],
Plot[c1*Sqrt[x]+c2*1+c3*x+c4*x^2, {x, 0, 1}]}]

During evaluation of In[9]:= {1.26774,0.418237,-0.773401,0.25858}

Out[10]= ...PlotSnipped...

You might run that last one a few times because the behavior varies depending on the sample.

Please check this carefully for any errors

URL: ,

Subject (listing for 'Approximating (a+x)^0.5 using specific set of f...')
Author Date Posted
Approximating (a+x)^0.5 using specific set of f... Ofer 04/23/13 11:11am
Re: Approximating (a+x)^0.5 using specific set ... Bill Simpson 04/23/13 1:46pm
Re: Approximating (a+x)^0.5 using specific set ... hieron 04/23/13 2:45pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic