T O P I C R E V I E W |
razva |
Posted - 04/24/2006 : 08:15:22 AM Origin Version: 7.5 Pro SR5 Operating System:XP Pro SP2
I have made some calculus with Mathematica v5.0 and I obtained the result I was interested as a function of variable x. I need this function to plot it with Origin. Up to now I managed to make it by printing the result from mathematica on paper and then manually imputing the function in Origin function plot. The problem is now more complicated as i have more functions to plot and they are some big expressions and it takes me at least half an hour just to write them in Origin. So I need to make some import from Mathematica into Origin or at least to make some copy and paste for this functions. But it is not so easy as Mathematica is using a different text formating with symbols Origin does not understand. I have also tried to use OriginLink for Mathematica. The problem with this application is that it cannot plot my own defined function I have calculated in Mathematica. Or at least I do not know how to define so that both programs to know it by name. Please help me to solve this problem. Thnx |
7 L A T E S T R E P L I E S (Newest First) |
Mike Buess |
Posted - 05/06/2006 : 12:24:29 PM Hi blocho,
If there were a line return instead of a comma after each {x,y} pair you could import easily with the Import Wizard as follows...
1. Open the IW and select your file. 2. Click Next>> and enter Number of header lines (probably 0). 3. Click Next>> and set Delimiter to Comma and Number of columns to 2. Click Apply. 4. Click Next>> and make sure Non-numeric data in a numeric field is set to Read as Text. 5. Click Next>> and check Save filter, enter path, filter name and other specifics and check Specify advanced filter options. 6. Click Next>> and enter the following lines in the LabTalk code box.
loop(i,1,wks.maxrows) { %A=cell(i,1)$; cell(i,1)$=%[%A,>2]; %A=cell(i,2)$; cell(i,2)$=%[%A,%[%A]]; };
7. Click Finish.
If the {x,y} pairs are actually separated by commas then you can read the file as a single line and parse the resulting string into a worksheet. That's possible with an Origin C function like this...void test() { string strFile = GetOpenBox("*.dat"); if( !strFile.IsFile() ) return; string strText,str; stdioFile ff(strFile, file::modeRead); ff.ReadString(strText); ff.Close(); if( strText.IsEmpty() ) return; int nPairs = strText.GetNumTokens(','); Worksheet wks; wks.Create(); for(int i=0; i<nPairs; i++) { str = strText.GetToken(i,','); wks.SetCell(i,0,str.GetToken(0,',')); wks.SetCell(i,1,str.GetToken(1,',')); } } quote: The Mathematica link tool doesn't work with my version of Origin (7.5 but nor SR5).
Yes, that's stated explicitly in the description. Patches are free so your might as well get SR6... http://www.originlab.com/index.aspx?s=9&lm=76
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/06/2006 12:27:24 PM |
blocho |
Posted - 05/05/2006 : 11:31:43 AM Hi easwar,
I found the way to export from Mathematica 5.2 the data to diffrent formats. I got the data, however, in such a form that Origin doesn't want to read it (or I don't know how to do it). The data exported from Mathematica are (in the best case) in the following form:{x1, y1}, {x2, y2},... (this is a .dat file). No export command allow to export the data in the form of a table. How to load such data into Origin?
The Mathematica link tool doesn't work with my version of Origin (7.5 but nor SR5).
Edited by - blocho on 05/05/2006 11:34:04 AM |
easwar |
Posted - 05/03/2006 : 10:22:50 AM quote:
could you write, please, the command(s) that allow in Mathematica creating the x and y values as ASCII file?
Hi blocho,
I do not know those commands...Try the Mathematica help file, or their forum/support?
Why not use the Mathematica link tool instead? You could simply "get" the data into Origin rather than going thru disk file? The process of writing to disk and importing in Origin was only a last-resort step in my suggestion earlier...
Easwar OriginLab
|
blocho |
Posted - 05/03/2006 : 09:46:09 AM Hi easwar,
could you write, please, the command(s) that allow in Mathematica creating the x and y values as ASCII file? I have a very long implicit equation (f(x,y)=0) and generated the curve in Mathematica. Next, I want to create the x and y values (a lot of them to obtain high quatily of the plot) and, finally, open the ASCII file in Origin.
The script for the implicit function plots is not suitable for such huge equations.
|
easwar |
Posted - 05/02/2006 : 2:12:54 PM Hi blocho,
All I meant was that, in Mathematica, once a function is defined, using some Mathematica commands one could generate an x and an f(x) dataset and export that to say an ASCII file and then read into Origin.
So for example, in Mathematica, one could do: myfunc[x_] := x^3 + 4 v1 = {1, 2, 3, 4, 5, 6, 7, 8, 9} v2 = myfunc[v1] for example, to compute using a defined function.
But more efficient of course is to to save the function definition and then load that using Evaluate tab in Origin tool.
Easwar OriginLab
|
blocho |
Posted - 05/02/2006 : 12:11:14 PM "There is always the option of course of also creating the X, Y data arrays in Mathematica and exporting that to an ascii file and importing this data file into Origin to plot, but the above way of saving the Mathematica function to file and loading back into the kernel using the link tool should work fine."
Could you explain how to create the x, y data arrays in Mahematica, please?
|
easwar |
Posted - 04/26/2006 : 09:27:27 AM Hi razva,
First of all, copying Mathematica function expressions into Origin/Origin C may not work correctly due to notation differences.
So using the Mathematica Link to exchange the information is a better way.
Now, are you trying to run Origin and Mathematica side by side and have them communicate with each other,using the Sequencer instead of MathKernel? If yes, that seems to be broken in Origin 7.5+Mathematica 5.0
So I suggest the following:
1> Run Mathematica and do your computation and generate the function
2> Save the Mathematica function to an external file. You can do this with the Save command in Mathematica such as:
myfunc[x__] = 4.5 + 1.2*x + 0.7*x^2 Save["c:\\temp\\myfunction", myfunc]
which will save the function myfunc to a file called myfunction in c:\temp Note that then in Mathematica itself you can load back the function at any time using
<< "c:\\temp\\myfunction"
3> Change the Mathematical Link tool in Origin so that it works with MathKernel and not Sequencer - see the "OriginLinkForMathematica.pdf" file that we provide with the link. Basically you can do this by editing the OriginML.ini file in your user files folder and change sequencer.exe to mathkernel.exe
4> Launch Origin and bring up the link tool (at this point you could have Mathematica application still running, but Origin will not communicate with that instance)
5> Go to Evaluate tab of the link tool and load in the math function you saved, using the command below and clicking the Evaluate button:
<< "c:\\temp\\myfunction"
6> Now you can go to the Function tab and use your function name myfunc[x], specify start, end and number of points for x, and make the plot in Origin
There is always the option of course of also creating the X, Y data arrays in Mathematica and exporting that to an ascii file and importing this data file into Origin to plot, but the above way of saving the Mathematica function to file and loading back into the kernel using the link tool should work fine.
Hope this helps.
Easwar OriginLab
Edited by - easwar on 04/26/2006 09:33:33 AM |
|
|