Message Boards Message Boards

0
|
4811 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Construct a surface using NonlinearModelFit?

Posted 5 years ago

Hello everyone.

I have a matrix 40000*3. The first column are X positions, the second, Y positions and the third, values of f(x, y). I have used NonlinearModelFit to find a polynomial which fits said data (called F). The problem is that I need a huge number of terms. I have been asked to plot this new surface using Matlab.

I would like to know if it is possible to evaluate the polynomial F at the points defined by the pairs X and Y positions obtaining as a result a vector of size 40000*1 which later on I can export to Matlab, where I can use a contourf.

I have also tried to copy the plynomial by hand as:

for i=1:number_of_points
    w_x_1_reconstructed(i)=-5.63591*x(i)+0.324034*x(i)^2-0.00683514*x(i)^3+0.0000485218*x(i)^4+710.999*y(i)-54.1068*x(i)*y(i)+1.47658*x(i)^2*y(i)-0.0174122*x(i)^(3)*y(i)+0.0000711661*x(i)^4*y(i)+27.2783*y(i)^2-1.79134*x(i)*y(i)^2+0.0390551*x(i)^2*y(i)^2-0.000305961*x(i)^3*y(i)^2+(4.60362*10^(-7))*x(i)^4*y(i)^2+0.372277*y(i)^3-0.0206956*x(i)*y(i)^3+0.000304779*x(i)^2*y(i)^3+(3.15853*10^(-7))*x(i)^3*y(i)^3-(2.24926*10^(-8))*x(i)^4*y(i)^3+0.00164353*y(i)^4-0.00006926*x(i)*y(i)^4+(2.79603*10^(-8))*x(i)^3*y(i)^4-(2.70495*10^(-10))*x(i)^4*y(i)^4;  
end

but the resulting figure looks nothing at all as the original f(x, y). I am attaching my .nb file in case it is helpful.

Any advice on how to proceed is appreciated. Thanks.

Attachments:
POSTED BY: Jaime de la Mota
6 Replies
Posted 5 years ago

I hope you can understand why it's hard to give you specific advice on this question and your other recent question. You mention using 3 pieces of software (Mathematica, MATLAB, and AMPL) and not an explanation as to why you need 3 pieces of software. You mention AMPL for "optimizing" a function but Mathematica certainly has several flavors of optimizing functions.

So my question to you is "Why not just use Mathematica for everything?" Without a more complete idea of what you're trying to do, it's just hard to give appropriate advice.

POSTED BY: Jim Baldwin

Well, during my degree studies I learnt Matlab, that is the software with which I am more comfortable. Now, my boss prefers mathematica, so I am slowly learning,even though I am still quite unfamiliar and working on mathwork's examples. Same thing happens with AMPL, it is one of the most used optimizations softwares out there, I started using it a couple of months ago, but since my coworkers have been using it for a long time, I have been able to adapt their code and learn to work on it.

POSTED BY: Jaime de la Mota
Posted 5 years ago

Sorry, I wasn't criticizing the use of 3 different pieces of software. I was trying to understand why all 3 were needed. You've now explained the history but that's still not specifically related to the complete problem you're trying solve.

POSTED BY: Jim Baldwin

Don't worry; you have helped me. I think you have right to ask.

As I stated in my other post, I have a file with data which analytic expression is unknown but I need to later on use on AMPL. What you see here is the fit constructed using a ploynomial of high order.

POSTED BY: Jaime de la Mota
Posted 5 years ago

Hi Jaime,

Have you tried plotting the fit and the data points in Mathematica? Something like

Show[Plot3D[
  NLMX1R[x, y], {x, Min@XPos, Max@XPos}, {y, Min@YPos, Max@YPos}, 
  PlotRange -> All], Graphics3D[{PointSize[0.01], Point[TX1R]}]]
POSTED BY: Rohit Namjoshi

Thanks. It works fine.

POSTED BY: Jaime de la Mota
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract