% f = (term1+term2).*a(3)+ a(4) ;
% f= ((data(1,:).^2)/(a(1)^2)) + ((data(2,:).^2)/(a(2)^2));
% f= data(:,1).^2 .*a(1) + data(:,2).^2 .*a(2);.^( a(5)/a(4
end
I have generated data (parabolic) using a script like so:
function [x,y,z,xx,yy,zz] = parabolic_surface_generate(a,b,n)
if nargin ==0
%Generate around (0,0,0) about n*2 points
%We assume a and b to be 1
n=20; a=1;b=1;
end
x= [-n:2:0; 0:2:n];
y= [-n:2:0; 0:2:n];
%computing y
z= ((x.^2)/a^2) + ((y.^2)/b^2);
%For Plotting
xx=x;yy=y;zz=z;
%Data
x=[x(1:end,1);x(1:end,2)];
y=[y(1:end,1);y(1:end,2)];
z=[z(1:end,1);z(1:end,2)];
end
Once, I've generated the data, I fit it by using a statement
like so,
data=[x;y];
[a,res]=lsqcurvefit(@super_fitting,a0,data,z)
So, I've gotten the following errors at different times
1) I get complex values of the co-efficients
2) I get an error like so,
??? Error using ==> qr
Complex sparse QR is not yet available.
Error in ==> aprecon at 57
RPCMTX = qr(TM(:,p));
Error in ==> trdog at 47
[R,permR] = feval(pcmtx,H,pcoptions,DM,DG,varargin{:});
Error in ==> snls at 345
[sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
Error in ==> lsqncommon at 231
[x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
Error in ==> lsqcurvefit at 186
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
I have got co-efficients of a superquadric for a fit at
other times.
Potential issues:
I save my scripts on a network drive and am using Matlab
using a common Egr license.
When I get this error, I usually go back to fitting a sphere
and then up my way to a Super quadric and sometimes it works
(???)
I am lost here and any help would be much appreciated. I
have spent a lot of time poring through the matlab archives
and am hoping John or somebody could help me with this.
Thanks,
M
Subject: Lsqcurvefit Issues for fitting Superquadrics
Most likely what is happening is that the function super_fitting is
returning complex values. This could be expected as you are computing
fractional powers in several of the terms. In order to avoid this, you
could use the upper and lower bounds for the input parameter 'a' on the call
to LSQCURVEFIT, and/or you could enforce bounds on the some of the terms in
your objective (for example, force term1+term2 to be greater than zero so
that ((term1+term2).^(a(5)/a(4)) is real).
I hope you find this helpful.
Hernan R
"Mayur Mudigonda" <mupstein@yahoo.com> wrote in message
news:g3fb62$p95$1@fred.mathworks.com...
> Hello,
>
> I am trying to fit superquadrics[A.H.Barr] to some data that
> I have and Im facing some difficulties.
>
> My objective function is defined as:
>
> function f= super_fitting(a,data)
> x=data(1,:);
> y=data(2,:);
> term1=((x/a(1)).^(2/a(5)));
> term2=((y/a(2)).^(2/a(5)));
> f= a(3)* ((1- ((term1+term2).^(a(5)/a(4))) .^ (a(4)/2))
>
> % f = (term1+term2).*a(3)+ a(4) ;
> % f= ((data(1,:).^2)/(a(1)^2)) + ((data(2,:).^2)/(a(2)^2));
> % f= data(:,1).^2 .*a(1) + data(:,2).^2 .*a(2);.^( a(5)/a(4
> end
>
> I have generated data (parabolic) using a script like so:
>
> function [x,y,z,xx,yy,zz] = parabolic_surface_generate(a,b,n)
>
> if nargin ==0
> %Generate around (0,0,0) about n*2 points
> %We assume a and b to be 1
> n=20; a=1;b=1;
> end
> x= [-n:2:0; 0:2:n];
> y= [-n:2:0; 0:2:n];
>
> %computing y
> z= ((x.^2)/a^2) + ((y.^2)/b^2);
> %For Plotting
> xx=x;yy=y;zz=z;
> %Data
> x=[x(1:end,1);x(1:end,2)];
> y=[y(1:end,1);y(1:end,2)];
> z=[z(1:end,1);z(1:end,2)];
> end
>
> Once, I've generated the data, I fit it by using a statement
> like so,
> data=[x;y];
> [a,res]=lsqcurvefit(@super_fitting,a0,data,z)
>
> So, I've gotten the following errors at different times
>
> 1) I get complex values of the co-efficients
> 2) I get an error like so,
>
> ??? Error using ==> qr
> Complex sparse QR is not yet available.
>
> Error in ==> aprecon at 57
> RPCMTX = qr(TM(:,p));
>
> Error in ==> trdog at 47
> [R,permR] = feval(pcmtx,H,pcoptions,DM,DG,varargin{:});
>
> Error in ==> snls at 345
> [sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
>
> Error in ==> lsqncommon at 231
> [x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
>
> Error in ==> lsqcurvefit at 186
> [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
>
>
> I have got co-efficients of a superquadric for a fit at
> other times.
>
> Potential issues:
> I save my scripts on a network drive and am using Matlab
> using a common Egr license.
>
> When I get this error, I usually go back to fitting a sphere
> and then up my way to a Super quadric and sometimes it works
> (???)
>
> I am lost here and any help would be much appreciated. I
> have spent a lot of time poring through the matlab archives
> and am hoping John or somebody could help me with this.
>
> Thanks,
> M
Subject: Lsqcurvefit Issues for fitting Superquadrics
Thank you so much. I appreciate your help. I tried setting
bounds but to the co-efficients but I dont think we can
compare real and imaginary numbers alike, so the compiler
checks with only the real part of the co-efficient. So, is
there some way I can set the imaginary part of the
co-efficient to 0i?
Also, I tried fitting with the same function and now I dont
get any co-efficients for the superquadric function. I just
get 1's, while when I try to fit a sphere (which is a
superquadric with exponential co-efficients set to 1) it works.
Could you help?
Thanks,
Mayur
"Hernan Romero" <hromero@mathworks.com> wrote in message
<g3gpls$gri$1@fred.mathworks.com>...
> Mayur,
>
> Most likely what is happening is that the function
super_fitting is
> returning complex values. This could be expected as you
are computing
> fractional powers in several of the terms. In order to
avoid this, you
> could use the upper and lower bounds for the input
parameter 'a' on the call
> to LSQCURVEFIT, and/or you could enforce bounds on the
some of the terms in
> your objective (for example, force term1+term2 to be
greater than zero so
> that ((term1+term2).^(a(5)/a(4)) is real).
>
> I hope you find this helpful.
>
> Hernan R
>
> "Mayur Mudigonda" <mupstein@yahoo.com> wrote in message
> news:g3fb62$p95$1@fred.mathworks.com...
> > Hello,
> >
> > I am trying to fit superquadrics[A.H.Barr] to some data that
> > I have and Im facing some difficulties.
> >
> > My objective function is defined as:
> >
> > function f= super_fitting(a,data)
> > x=data(1,:);
> > y=data(2,:);
> > term1=((x/a(1)).^(2/a(5)));
> > term2=((y/a(2)).^(2/a(5)));
> > f= a(3)* ((1- ((term1+term2).^(a(5)/a(4))) .^ (a(4)/2))
> >
> > % f = (term1+term2).*a(3)+ a(4) ;
> > % f= ((data(1,:).^2)/(a(1)^2)) + ((data(2,:).^2)/(a(2)^2));
> > % f= data(:,1).^2 .*a(1) + data(:,2).^2 .*a(2);.^( a(5)/a(4
> > end
> >
> > I have generated data (parabolic) using a script like so:
> >
> > function [x,y,z,xx,yy,zz] =
parabolic_surface_generate(a,b,n)
> >
> > if nargin ==0
> > %Generate around (0,0,0) about n*2 points
> > %We assume a and b to be 1
> > n=20; a=1;b=1;
> > end
> > x= [-n:2:0; 0:2:n];
> > y= [-n:2:0; 0:2:n];
> >
> > %computing y
> > z= ((x.^2)/a^2) + ((y.^2)/b^2);
> > %For Plotting
> > xx=x;yy=y;zz=z;
> > %Data
> > x=[x(1:end,1);x(1:end,2)];
> > y=[y(1:end,1);y(1:end,2)];
> > z=[z(1:end,1);z(1:end,2)];
> > end
> >
> > Once, I've generated the data, I fit it by using a statement
> > like so,
> > data=[x;y];
> > [a,res]=lsqcurvefit(@super_fitting,a0,data,z)
> >
> > So, I've gotten the following errors at different times
> >
> > 1) I get complex values of the co-efficients
> > 2) I get an error like so,
> >
> > ??? Error using ==> qr
> > Complex sparse QR is not yet available.
> >
> > Error in ==> aprecon at 57
> > RPCMTX = qr(TM(:,p));
> >
> > Error in ==> trdog at 47
> > [R,permR] =
feval(pcmtx,H,pcoptions,DM,DG,varargin{:});
> >
> > Error in ==> snls at 345
> > [sx,snod,qp,posdef,pcgit,Z] =
trdog(x,g,A,D,delta,dv,...
> >
> > Error in ==> lsqncommon at 231
> > [x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
> >
> > Error in ==> lsqcurvefit at 186
> > [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
> >
> >
> > I have got co-efficients of a superquadric for a fit at
> > other times.
> >
> > Potential issues:
> > I save my scripts on a network drive and am using Matlab
> > using a common Egr license.
> >
> > When I get this error, I usually go back to fitting a sphere
> > and then up my way to a Super quadric and sometimes it works
> > (???)
> >
> > I am lost here and any help would be much appreciated. I
> > have spent a lot of time poring through the matlab archives
> > and am hoping John or somebody could help me with this.
> >
> > Thanks,
> > M
>
>
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.