Cun Zhang’s Blog

October 3, 2008

Start Matlab from console under Unix/Linx

Filed under: Linux, Math — Tags: , — Cun Zhang @ 21:48

Under Unix/Linux, you can run matlab without GUI,which always is so usefully for me.

For me, I run Matlab programs for long time in a remote server. If a Matlab  GUI is opened ,I can’t disconnect the remote server. But when I run Matlab without GUI, I can do it with screen command.

Here is a example:

cunzhang@node31:~$ screen -S a

Then enter a visual terminal

cunzhang@node31:~$matlab -nodisplay -r  myprogram

Now you can disconnect your remote server.If you want to see whether your program is done, just run command

cunzhang@node31:~$ screen -r a

For more information, please see:

1. GNU screen’s homepage

2. http://gentoo-wiki.com/TIP_Using_screen

3. http://sunsite.ualberta.ca/Documentation/Gnu/screen-3.9.4/html_chapter/screen_toc.html

4. matlab function reference

June 9, 2008

save plot into tex format in Octave

Filed under: Math, latex — Tags: , , — Cun Zhang @ 17:17

The print command in Octave is so useful! It can save plot into so many format, especially tex which can be used into these articles which are written by tex.

Another use for me is to make  program(mfile,which plot so many plots)  automatization become true.

e.g.

for i=0:2

x=[i:0.01:i+2]*pi;

plot(x,sin(x));

file=[num2str(i) '.jpg'];

print(file, ‘-djpeg’ );

end

close

Save these code into a mfile(e.g, a.m) ,then at the console,run the command:

octave a.m

Another way is to run a.m in Octave console.

Is it amazing? If it be useful for you, please tell me :)

May 26, 2008

在matlab里读取多个文件的数据(转)

Filed under: Math — Tags: , , , — Cun Zhang @ 11:33

注:在Octave里运行很多程序,然后将每个程序的结果存到不同的文件里。上网上找到这篇文章,终于将那个问题搞定。谢谢那位朋友的帖子!特转载之。

原文地址:http://www.myclub2.com/blog/realghost/archive/2007/09/23/45972.html

在一个matlab的学习群里,有人提出了这么一个问题:在matlab里如何读取多信文件的数据,例如,有许多数据,存放在不同的txt文件里。

我的办法是把这些文件的文件名按一定的规律命名,假如有一百个数据文件,则可以把这些文件分别命名为:filename1.txt,filename2.txt,…,fielname100.txt,在读取的时候则可以使用循环:

for i = 1:100

fileName = ['filename' num2str(i) '.txt'];

x = load(fileName);

end

但另一位朋友给出了另一个解决的办法,无需对数据文件的文件名进行修改,就是文件名无须有规律,他的办法是:

A = dir(fullfile(’d:\datafile’,'*.txt’));

这个语句是把存放数据文件的目录d:\datafile下的所有txt文件列出来,并把这些文件名的信息存放到一个变量A中,A是一个结构体变量,只要对A进行循环就可以读取到所有文件的数据了。

所谓人外有人,山外有山,我真是受教了,特写此文以记录此法。

附:help fullfile

help fullfile
FULLFILE Build full filename from parts.
FULLFILE(D1,D2, … ,FILE) builds a full file name from the
directories D1,D2, etc and filename FILE specified. This is
conceptually equivalent to

F = [D1 filesep D2 filesep ... filesep FILE]

except that care is taken to handle the cases where the directory
parts D1, D2, etc. may begin or end in a filesep. Specify FILE = ”
to build a pathname from parts.

Examples
To build platform dependent paths to files:
fullfile(matlabroot,’toolbox’,'matlab’,'general’,'Contents.m’)

To build platform dependent paths to a directory:
addpath(fullfile(matlabroot,’toolbox’,'matlab’,”))

See also filesep, pathsep, fileparts.
Reference page in Help browser
doc fullfile

May 3, 2008

Vector Operation in Maxima

Filed under: Math — Tags: , — Cun Zhang @ 16:53

/*
wxMaxima 0.7.5 http://wxmaxima.sourceforge.net
Maxima 5.15.0 http://maxima.sourceforge.net
Using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (aka GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) load(”vect”);
(%o1) d:/PROGRA~1/MAXIMA~1.0/share/maxima/5.15.0/share/vector/vect.mac
(%i2) demo(”vect”);
batching #pd:/PROGRA~1/MAXIMA~1.0/share/maxima/5.15.0/share/vector/vect.dem
At the _ prompt, type ‘;’ followed by enter to get next demo
(%i3) if get(’vect,’version)=false then load(vect)
_ ;
(%i4) declare([p,q,f,g],nonscalar)
_ ;
(%i5) f~p.q~g+q~f.p~g+p~q.f~g=0
(%o5) f.(-(-g)~q)~p-f.(-(-g)~p)~q+f.g~p~q=0
_ ;
(%i6) ev(vectorsimp(%),expandall)
(%o6) 0=0
_ ;
(%i7) example:laplacian(%pi*(h+s))=div(3*s*p)
(%o7) %pi*laplacian(s+h)=3*div(p*s)
_ ;
(%i8) ev(vectorsimp(example),expandall:true)
(%o8) %pi*laplacian(s)+%pi*laplacian(h)=3*div(p)*s+3*(p.grad(s))
_ ;
(%i9) parabolic:[[(u^2-v^2)/2,u*v],u,v]
(%o9) [[(u^2-v^2)/2,u*v],u,v]
_ ;
(%i10) scalefactors(parabolic)
_ ;
(%i11) example:express(example)
(%o11)(%pi*(’diff((s+h),v,2)+’diff((s+h),u,2)))/(v^2+u^2)

=(3*(’diff((s*sqrt(v^2+u^2)*p[v]),v,1)+’diff((s*p[u]*sqrt(v^2+u^2)),u,1)))/(v^2+u^2)
_ ;
(%i12) depends([s,h],u,[s,p],v)
_ ;
(%i13) ev(example,diff,factor)
(%o13) (%pi*(’diff(s,v,2)+’diff(s,u,2)+’diff(h,u,2)))/(v^2+u^2)=
(3*(s*v^2*(’diff(p[v],v,1))+s*u^2*(’diff(p[v],v,1))+(’diff(s,v,1))*v^2*p[v]+s*v*p[v]

+(’diff(s,v,1))*u^2*p[v]+(’diff(s,u,1))*p[u]*v^2+(’diff(s,u,1))*u^2*p[u]+s*u*p[u]))/(v^2+u^2)^(3/2)
_ ;
(%i14) example:[(3*u^3*v+2*u*v^3)/(u^2+v^2),(u^4+2*u^2*v^2)/(v^2+u^2)]
(%o14) [(2*u*v^3+3*u^3*v)/(v^2+u^2),(2*u^2*v^2+u^4)/(v^2+u^2)]
_ ;
(%i15) potential(example)
(%o15) u^2*v*sqrt(v^2+u^2)
_ ;
(%o16) d:/PROGRA~1/MAXIMA~1.0/share/maxima/5.15.0/share/vector/vect.dem

April 26, 2008

Tensor software

Filed under: Math — Tags: , , — Cun Zhang @ 14:49

I have been searching Tensor software so long time, but collect a few before searching in wikipedia.
Here is a collection of tensor software from wikipedia.

  • FTensor is a high performance tensor library written in C++.
  • GRTensorII is a computer algebra package for performing calculations in the general area of differential geometry. GRTensor II is not a stand alone package, the program runs with all versions of Maple V Release 3 through Maple 9.5. A limited version (GRTensorM) has been ported to Mathematica.
  • MathTensor is a tensor analysis system written for the Mathematica system. It provides more than 250 functions and objects for elementary and advanced users.
  • Tensors in Physics is a tensor package written for the Mathematica system. It provides many functions relevant for General Relativity calculations in general Riemann-Cartan geometries.
  • maxima is a free computer algebra system which should be usable for making tensor algebra calculations
  • Ricci is a system for Mathematica 2.x and later for doing basic tensor analysis, available for free.
  • Tela is a software package similar to Matlab and Octave, but designed specifically for tensors.
  • Tensor Toolbox Multilinear algebra MATLAB software.
  • TTC Tools of Tensor Calculus is a Mathematica package for doing tensor and exterior calculus on differentiable manifolds.
  • EDC and RGTC “Exterior Differential Calculus” and “Riemannian Geometry & Tensor Calculus” are free Mathematica packages for tensor calculus especially designed but not only for general relativity.
  • Tensorial “Tensorial 4.0″ is a general purpose tensor calculus package for Mathematica. Already a mature package, Tensorial was successfully applied in a broad range of fields including general relativity, continuum mechanics. A PDF image can be found at this web address .
  • Cadabra “Cadabra” is a computer algebra system (CAS) designed specifically for the solution of problems encountered in field theory. It has extensive functionality for tensor polynomial simplification including multi-term symmetries, fermions and anti-commuting variables, Clifford algebras and Fierz transformations, implicit coordinate dependence, multiple index types and many more. The input format is a subset of TeX. Both a command-line and a graphical interface are available.
Older Posts »

Powered by WordPress