diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..56269a1 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# matlab-plugin documentation + +I have written documentation files for the Matlab-plugin + * matlab.en.tm + * matlab-abstract.en.tm (basically an adaptation of Joris van der Hoeven's octave-abstract.en.tm) + * matlab-install.en.tm (an installation and configuration instruction) + The startup script included therein is the result of a collaborative effort by jeroen, pireddag, + and me on http://forum.texmacs.cn/t/getting-the-matlab-plugin-working-with-texmacs/368) + * matlab-demo.en (a short guide to show the working of the Matlab-plugin) + +jeroen, pireddag, and me wrote the script file + * tm_matlab + +If they are considered useful, I offer them to be included for public use. +Feedback on any shortcomings, inconsistencies or (blatant) errors is more than appreciated. + +Tilda A. Steiner diff --git a/bin/tm_matlab b/bin/tm_matlab index a4bb419..999e9ee 100755 --- a/bin/tm_matlab +++ b/bin/tm_matlab @@ -1,4 +1,10 @@ -#!/bin/sh -echo -ne "\002verbatim:" -cd $TEXMACS_PATH/plugins/matlab/code -matlab -nojvm -r tmrepl +#!/bin/bash + echo -ne "\002verbatim:" + +# location of plugin-config (tmrepl.m) +# PLUGIN_CODE=$TEXMACS_HOME_PATH/plugins/matlab/code/ + PLUGIN_CODE_PATH=$TEXMACS_PATH/plugins/matlab/code/ +# extend and export MATLABPATH + export MATLABPATH="$MATLABPATH:$PLUGIN_CODE_PATH" +# start Matlab for plugin session + matlab -nodesktop -nosplash -r tmrepl diff --git a/doc/matlab-abstract.en.tm b/doc/matlab-abstract.en.tm new file mode 100644 index 0000000..097c54a --- /dev/null +++ b/doc/matlab-abstract.en.tm @@ -0,0 +1,46 @@ + + +> + +<\body> + system> + + is a high-level language, primarily intended for numerical + computations. It provides a convenient command line interface for solving + linear and nonlinear problems numerically, and for performing other + numerical experiments using a language that is mostly compatible with + . It may also be used as a batch-oriented language. + + has extensive tools for solving common numerical linear + algebra problems, finding the roots of nonlinear equations, integrating + ordinary functions, manipulating polynomials, and integrating ordinary + differential and differential-algebraic equations. It is easily extensible + and customizable via toolkits and user-defined functions written in + 's own language, or using dynamically loaded modules written + in C++, C, Fortran, or other languages. + + The interface to has been written by way back in 2004 and undergone some reorganization by J in early 2013. Despite its age, it can still be run with + more recent version of . A group of enthusiast (pireddag, + jeroen, and Tilda) on have worked on the necessary + modifications to get the plugin up and going. Time will tell, if + recoding is required. So, if you like the idea of using + from within , then please help figuring out. + + specifics by Tilda Steiner> + + + + +<\initial> + <\collection> + + + \ No newline at end of file diff --git a/doc/matlab-demo.en.tm b/doc/matlab-demo.en.tm new file mode 100644 index 0000000..3e84b1b --- /dev/null +++ b/doc/matlab-demo.en.tm @@ -0,0 +1,538 @@ + + +> + +<\body> + <\tmdoc-title> + A Sample session + + + A session is started by using .\ + + <\session|matlab|default> + <\output> + \; + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ M A T + L A B (R) \ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Copyright 1984-2020 The MathWorks, + Inc. + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ R2020a Update 6 (9.8.0.1538580) 64-bit + (maci64) + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ November 23, + 2020 + + \ + + <\with|par-mode|center> + To get started, type doc. + + + <\with|par-mode|center> + For product information, visit www.mathworks.com. + + + + <\input|Matlab] > + \; + + + + for Linear Algebra Computations> + + At the plugin prompt, commands can be inserted both in + single-line and multi-line input mode. The way to enter multi-line commands + is by pressing the -keys simultaneously. Below, we show + how to do some linear algebra operations with , like\ + + <\session|matlab|default> + <\unfolded-subsession> + vector projections (\>* of > onto + >) + <|unfolded-subsession> + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ u = [3 5]; + + \ v = [7 2]; + + \ dot(u,v)/(norm(v))^2*v + <|unfolded-io> + >|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + + + <\session|matlab|default> + <\unfolded-subsession> + matrix operations (display, transpose, invert a matrix, calculate its + det>>, rg>, and eigenvectors) + <|unfolded-subsession> + <\session|matlab|default> + <\input> + matlab\\ + <|input> + \ A=[1 0 0 0; 1 1 0 0; 1 2 1 0; 1 3 3 1] + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ tmdisp(A) + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + A' + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + + <\session|matlab|default> + <\unfolded-io> + matlab\\ + <|unfolded-io> + inv(A) + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + A*inv(A) + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ det(A) + <|unfolded-io> + + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ rank(A) + <|unfolded-io> + + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ eig(A) + <|unfolded-io> + >>|>>|>>|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + + + + <\session|matlab|default> + <\unfolded-subsession> + power operations on matrices + <|unfolded-subsession> + <\unfolded-subsession> + taking the -th power of a matrix + |)>> + <|unfolded-subsession> + <\unfolded-io> + matlab\\ + <|unfolded-io> + A*A*A + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\unfolded-io> + matlab\\ + <|unfolded-io> + A^3 + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + \; + + + <\unfolded-subsession> + taking each element > of > to the + -th power + <|unfolded-subsession> + <\unfolded-io> + matlab\\ + <|unfolded-io> + A.^3 + <|unfolded-io> + >|>|>|>>|>|>|>|>>|>|>|>|>>|>|>|>|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + \; + + + + + <\session|matlab|default> + <\unfolded-subsession> + solving linear systems in the form **\=\*> + <|unfolded-subsession> + <\unfolded-io> + matlab\\ + <|unfolded-io> + \ C=[2 1 1 1; 1 2 1 1; 1 1 2 1; 1 1 1 2]; b=[1,2,3,4]'; + + \ x=linsolve(C,b); + + \ tmdisp(x) + <|unfolded-io> + >>|>>|>>|>>>>>> + + + <\input> + matlab\\ + <|input> + \; + + + + + Note that the only displays output when it is not + assigned to a variable, unlike what happens in 's command + window, where the results of all commands that do not terminate with a + semicolon are displayed. The command , for instance, assigns the matrix + to the variable . As the + command is a variable assignment, the plugin will not display the output + that is contained in variable .<\footnote> + The reason being, in a nut shell, that the plugin via the display command + in , lines 11\U15, notices that has an + old value (e.> the string , + f.> line 11). Thus the plugin does not display + anything, even though the command has been executed and the variable + has been defined. Yet, the result assigned to . + So, to force , i.e. the matrix in variable + , to be displayed, you will either have to use + or to have it nicely formatted.\ + + The command performs an on the + previously \Pdefined\Q variable , in this case taking the 3rd + power on matrix >>. The answer, and the + variable, will then be displayed automatically by the plugin.<\footnote> + The evaluated result of an operation assigned to + (f. >, lines + 12f.). This is because these operations produce a new value + for (, f>. + , line 13. Hence, when performing such + operations, no command is needed, as the work is + already being done by , f. + >, line 14. \V Credit for this needs to go to Giovanni + Piredda, who meticulously pointed out the workings of + to me in much more detail. + + + as a Plotting Engine> + + In this section we give some 2d and 3d specimens of 's + plotting features. Using a file is not mandatory, but + it helps, among others, to ensure consistency among the figures. So, some + formatting instructions have been outsourced to a + file, that is read-in on starting a -session: + + <\shell-code> + + % startup.m + + \; + + % Set grids on all axes. + + \ \ set(0,'defaultAxesXGrid','on'); + + \ \ set(0,'defaultAxesYGrid','on'); + + \ \ set(0,'defaultAxesZGrid','on'); + + \; + + % Font size + + \ \ set(0,'DefaultTextFontSize',14); + + \ \ set(0,'DefaultAxesFontSize',14); + + \; + + % LaTeX fonts + + \ \ set(groot,'defaultAxesTickLabelInterpreter','latex'); \ + + \ \ set(groot,'defaulttextinterpreter','latex'); + + \ \ set(groot,'defaultLegendInterpreter','latex');\ + + \; + > + + + \ + + There is one draw back, however. Presently the does + not support inline plotting. So, the plots have to be saved to disk, and + then linked/inserted (in)to the -document. + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + \ x=linspace(-10,10,1000); + + \ y=x+sin(x); + + \ plot(x,y, 'linewidth', 2.0); + + \ legend({'y=x+sin(x)'},'Location','East'); + + + <\input> + matlab\\ + <|input> + \; + + + + \; + + <\with|par-mode|center> + |02_sinusoidal.eps>|0.618par|||> + + + It also possible to read-in and execute .files that are + somewhere in the and follow 's naming + conventions directly from the command line. So, running\ + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + vector_field_3d_plot + + + + which is an .file that contains the code below, is equivalent + to executing\ + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + x = linspace(-3, 3, 10); + + y = x; + + z = x; + + [X Y Z] = meshgrid (x, y, z ); + + quiver3(X, Y, Z, ones(size(X)), ones(size(Y)), Z); + + set(gca, 'linewidth', 1.00); + + title('3d vector field'); + + + + on the command line. + + <\with|par-mode|center> + |vector-field-3d_plot-m100.eps>|0.618par|||> + + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + [x,y]=meshgrid(linspace(0,1,75)); + + surf(x,y,sin(8*pi*x).* exp(-20*(y-0.5).^2)+exp(-(x-0.5).^2*30 + -(y-0.25).^2 -(x-0.5).*(y-0.25))); + + set(gca, 'linewidth', 1.00); + + xlabel('x-axis'); + + ylabel('y-axis'); + + + <\input> + matlab\\ + <|input> + \; + + + + <\with|par-mode|center> + |SinExp-3d_plot.eps>|0.618par|||> + + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + [x, y] = meshgrid(-5:0.5:5); + + \ \ \ \ Zv = @(x,y) 1 - x - y;\ + + mesh(x,y,Zv(x,y)); + + hold on; + + [x, z] = meshgrid(-5:0.5:5); + + \ \ \ \ Yv = @(x) 2*x; + + surf(x,Yv(x),z); + + hold off; + + shading interp; + + view(110,25); + + set(gca, 'linewidth', 1.00); + + title('Intersecting planes in ${R^3}$'); + + xlabel('x-axis'); + + ylabel('y-axis'); + + zlabel('z-axis'); + + + <\input> + matlab\\ + <|input> + \; + + + + <\with|par-mode|center> + |04_intPlanes.eps>|0.618par|||> + + + \; + + > + + The plugin allows for the calling of functions from additional + toolkits. Coming back to the first example of our tour, we + have used 's freely available + toolbox () + to plot the vector projection calculated above.\ + + <\session|matlab|default> + <\input> + matlab\\ + <|input> + u = [3 5]'; + + v = [7 2]'; + + dot(u,v)./(norm(v)).^2*v; + + puv = dot(u,v)./(norm(v)).^2*v; + + drawVector([u v puv], {'u','v','{ }'});\ + + hold on;\ + + drawSpan(u);\ + + hold on;\ + + drawLine([u puv], 'r-.'); + + hold off; + + title('Vector projection \\textbf{u*} of \\textbf{u} onto + \\textbf{v}'); + + + <\input> + matlab\\ + <|input> + \; + + + + <\with|par-mode|center> + |vectProj-u2v.eps>|0.618par|||> + + + session> + + At least on Mac OSX, it is a good idea to close the + -app on the dashboard and via the button within . This would shut down the + -app causing an \Pabnormal termination\Q due to a + \Psegmentation violation\Q and clutter your directory with + -files.\ + + Steiner> + + + + +<\initial> + <\collection> + + + \ No newline at end of file diff --git a/doc/matlab-install.en.tm b/doc/matlab-install.en.tm new file mode 100644 index 0000000..4c3d19f --- /dev/null +++ b/doc/matlab-install.en.tm @@ -0,0 +1,128 @@ + + +> + +<\body> + + + The is a built-in plugin in GNU . It assumes + that is installed on your system. If + is not available, do the + following: + + <\enumerate> + Check if is installed, if not, you will need to + install first. + + Check if command line is in your system path + () + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (url-exists-in-path? "matlab") + <|unfolded-io> + #t + + + <\input|Scheme] > + \; + + + + if not (e.> ), add the directory where + resides to your . + + The way to do this on X> is to create a + softlink to it by issuing\ + + + sudo ln -sf /Applications/MATLAB_R2020a.app/bin/matlab + /usr/local/bin/matlab + > + + This should work in a similar way on other Unix systems and with other + versions of . Now that you have in your + , will show up. + + As you probably need to customize the , you + will want to install it under the : + + + # For GNU/Linux or macOS + + git clone git@github.com:texmacs/matlab.git + $HOME/.TeXmacs/plugins/matlab + + \; + + # For Windows + + git clone git@github.com:texmacs/matlab.git + %APPDATA%\\TeXmacs\\plugins/matlab + > + + Users who do not know about Git can also download the zip-file from + Github and unzip to the corresponding directory. + + Then, it is critical to make sure that the -startup + script in + looks like this:\ + + + <\shell-code> + + # For GNU/Linux or macOS + + \; + + \ #!/bin/bash + + \ \ \ echo -ne "\\002verbatim:" + + \ \ \ PLUGIN_CODE_PATH=$TEXMACS_PATH/plugins/matlab/code/ + + \ \ \ export MATLABPATH="$MATLABPATH:$PLUGIN_CODE_PATH" + + \ \ \ matlab -nodesktop -nosplash -r tmrepl + + \; + > + + + \; + + <\shell-code> + + # For Windows + + \ \ + + ?? tm_matlab.bat ?? Isn't there a bash shell for Windows? + + \; + > + + + If not, you may to + accordingly. This ensures that is added to the + original as defined by , and that both + are exported when launching a -session from within + . Thus, any user defined configuration in a + , if there is one, will be considered. you're + up and running. + + Steiner> + + + + +<\initial> + <\collection> + + + \ No newline at end of file diff --git a/doc/matlab.en.tm b/doc/matlab.en.tm index 8de99d7..a4a98dd 100644 --- a/doc/matlab.en.tm +++ b/doc/matlab.en.tm @@ -1,11 +1,21 @@ - + - +> <\body> plug-in> - + <\traverse> + <\branch> + Short description + + + + + + + +