Prev: Uploading Data
Next: Friction simulation
From: John on 10 Feb 2010 22:50 If I have an x,y,z matrix such as: x y z 1 10 500 2 10 700 3 10 800 1 20 750 2 20 850 3 20 950 How can I correctly implement the LSQCURVEFIT command: X = LSQCURVEFIT(FUN,X0,XDATA,YDATA,LB,UB,OPTIONS) I need the equation relating these points in a 3d space so i can create a nice surf or mesh plot. Inside the function fun, I want to use the cost function: F = a(1)*x + a(2)*y + a(3)*x*y + a(4)*x^2*y +a(5)*x*y^2 to find the coefficients. and Initially set XO=0. Be excellent to each other and party on.
From: John D'Errico on 10 Feb 2010 23:49 "John " <tarpoon7(a)gmail.com> wrote in message <hkvups$sr1$1(a)fred.mathworks.com>... > If I have an x,y,z matrix such as: > x y z > 1 10 500 > 2 10 700 > 3 10 800 > 1 20 750 > 2 20 850 > 3 20 950 > > How can I correctly implement the LSQCURVEFIT command: > X = LSQCURVEFIT(FUN,X0,XDATA,YDATA,LB,UB,OPTIONS) > I need the equation relating these points in a 3d space so i can create a nice surf or mesh plot. > > Inside the function fun, I want to use the cost function: > F = a(1)*x + a(2)*y + a(3)*x*y + a(4)*x^2*y +a(5)*x*y^2 > to find the coefficients. > and Initially set XO=0. > > Be excellent to each other and party on. Don't bother using lsqcurvefit here. Why use a nonlinear regression tool to fit a linear model? Then you need to provide starting values, a silly thing if they are not really needed. Just download polyfitn from the file exchange. http://www.mathworks.com/matlabcentral/fileexchange/10065 John
From: awu PROM on 28 Feb 2010 12:07 Dear John I can not run your polyfitn.m file. There is still an error ??? Error: File: C:\MATLAB6p1\work\polyfitn.m Line: 141 Column: 24 Expected a variable, function, or constant, found "|". Could you fix it? "John " <tarpoon7(a)gmail.com> wrote in message <hkvups$sr1$1(a)fred.mathworks.com>... > If I have an x,y,z matrix such as: > x y z > 1 10 500 > 2 10 700 > 3 10 800 > 1 20 750 > 2 20 850 > 3 20 950 > > How can I correctly implement the LSQCURVEFIT command: > X = LSQCURVEFIT(FUN,X0,XDATA,YDATA,LB,UB,OPTIONS) > I need the equation relating these points in a 3d space so i can create a nice surf or mesh plot. > > Inside the function fun, I want to use the cost function: > F = a(1)*x + a(2)*y + a(3)*x*y + a(4)*x^2*y +a(5)*x*y^2 > to find the coefficients. > and Initially set XO=0. > > Be excellent to each other and party on.
From: John D'Errico on 28 Feb 2010 12:22 "awu PROM" <arwut365(a)hotmail.com> wrote in message <hme7rq$nub$1(a)fred.mathworks.com>... > Dear John > I can not run your polyfitn.m file. > There is still an error > ??? Error: File: C:\MATLAB6p1\work\polyfitn.m Line: 141 Column: 24 > Expected a variable, function, or constant, found "|". > Could you fix it? Can I fix it? Your matlab release is now about 10 years old if you are using version 6.1. Polyfitn was written since then, and it uses some things that were added to matlab. Sorry, I can't go back and make polyfitn run on your release, as it would then be less efficient for the thousands of people who use more modern releases. You can choose to go through the code and figure out what it does, repairing that which fails for your release. This would be possible I imagine, but hardly worth it. Instead, use another tool. Do you have the stats toolbox? If so, then use regress. Or, you can use backslash, or lscov, or lsqr, or a variety of other tools already in matlab. Each of these tools will require you to build the design matrix for this problem, and so learn something about linear regression in the process. John
|
Pages: 1 Prev: Uploading Data Next: Friction simulation |