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
 LabTalk Forum
 Interpolation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

P.G.

4 Posts

Posted - 03/04/2015 :  09:22:52 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2015
Operating System: Win 7

Hello everyone,

I am trying to wirte an LabTalk-Script and I need special values from an interpolation.

I have given data A and B and I use interp1 ix:= A iy:=B to create an interpolation of the Data.
Now i have a given value, lets say x which is somewhere between the Data in A so it must be in the interpolation of A and B and I want the corresponding value from B, which is here called y.
Is there a way to calculate the y value from the given x value in LabTalk?
I am trying to wirte a bigger Code so I can not use the tools that one can call "by hand", but only "by code".

Greetings

Sophy

China
Posts

Posted - 03/04/2015 :  9:19:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

Hi,

Origin C provides a function ocmath_interpolate(can search this by Find in Files in Code Builder, or refer to help file) to interpolate a value at specified position, you may wrap this function by write a simple Origin C function invokable to Labtalk(solution A), or write your own X-Function to call ocmath_interpolate(solution B).

A simple way(as suggested as solution A mentioned above) is to write a function in an Origin C file(make sure the Origin C file in added into workspace in Code Builder and built successfully, so the function can be called by Labtalk through Script Window).

double	user_interpolate_y_at_x(vector vX, vector vY, double xPos)
{
	double dYVal = 0;
	int nSrcSize = vX.GetSize();
	ASSERT(nSrcSize == vY.GetSize());
	int nRet = ocmath_interpolate(&xPos, &dYVal, 1, vX, vY, nSrcSize);
	if ( nRet != 0 )
		dYVal = NANUM;
	return dYVal;
}

then you can call the function like

dRet = user_interpolate_y_at_x(Book1_A, Book1_B, 3.2);

in Script Window, dRet contains the result.
quote:
Originally posted by P.G.

Origin Ver. 2015
Operating System: Win 7

Hello everyone,

I am trying to wirte an LabTalk-Script and I need special values from an interpolation.

I have given data A and B and I use interp1 ix:= A iy:=B to create an interpolation of the Data.
Now i have a given value, lets say x which is somewhere between the Data in A so it must be in the interpolation of A and B and I want the corresponding value from B, which is here called y.
Is there a way to calculate the y value from the given x value in LabTalk?
I am trying to wirte a bigger Code so I can not use the tools that one can call "by hand", but only "by code".

Greetings


Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 03/06/2015 :  3:04:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi P.G.,

You can also consider to use the XY data range as a function to get the interpolated Y value from given X. So, once you run interp1, then by using its result as a function, you can get new Y from a specific X. See:
http://www.originlab.com/doc/LabTalk/guide/Interpolation#Using_XY_Range

Does it help?

--Hideo Fujii
OriginLab
Go to Top of Page

P.G.

4 Posts

Posted - 03/10/2015 :  04:21:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes thank you everything looks good now.
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