The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 plotting polynoms
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ovince

Yugoslavia
Posts

Posted - 11/20/2006 :  07:30:11 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
hi,

Using a fitpoly() method, I got the coefficents of 2nd order polynom

Curve crv(x,y);
double coeff[2];
bool bRet=fitpoly(crv, 1, coeff);


Can I use them to overplot the polynom over the (already existing) graph and how?

Thanks
Oliver

Mike Buess

USA
3037 Posts

Posted - 11/20/2006 :  08:24:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Oliver,

Create a new column in the wks containing x and y. Fill column with values of the polynomial. Plot column in existing layer.

int colNum = wks.AddCol();
Dataset dx(wks,0); // X dataset
Dataset dy(wks,colNum); // Y dataset
for(int i=0; i<dx.GetSize(); i++)
{
dy[i] = coeff[0] + coeff[1]*dx[i];
}
Curve crv(wks,colNum);
gl.AddPlot(crv,IDM_PLOT_LINE); // gl is existing graph layer

Mike Buess
Origin WebRing Member
Go to Top of Page

ovince

Yugoslavia
Posts

Posted - 11/20/2006 :  09:35:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thanks Mike

something strange is happening in the for loop

int colNum = wks.AddCol();
Dataset dx(wks,0); // X dataset
Dataset dy(wks,colNum); // Y dataset
for(int i=0; i<dx.GetSize(); i++)
{
printf("%f\t %f\t %f\n", coeff[0], coeff[1], dx[i]);
dy[i] = coeff[0] + coeff[1]*dx[i];
}


Although, all values (coeff[0], coeff[1], dx[i])) are defined inside the loop (checked with print() ) dy[i] is not calculated. I have tried with changing the name dy[i] -> dyy[i] to be sure it does not exist but does not help


have any idea what to do?

oliver
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 11/20/2006 :  09:50:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try setting the size of dy before setting its values...

int colNum = wks.AddCol();
Dataset dx(wks,0); // X dataset
Dataset dy(wks,colNum); // Y dataset
dy.SetSize(dx.GetSize());

Mike Buess
Origin WebRing Member
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000