Symbolic notation for functions in Matlab - matlab

Is there a way to use actual symbols (like the square root symbol instead of writing "sqrt()" and integral and sum/product signs instead of "integrate", "sum", etc.) as in Mathematica?

Partially, but not within the main part of Matlab.
If you use MuPAD (type mupad in your Command Window), the engine behind much of the Symbolic Math toolbox, you can display/print results from calculations in your notebook with various levels of formatting. However, it does not appear that one can display what one enters with such formatting. Like Mathematica, MuPAD does have a graphical toolbar interface for selecting various commonly used types of mathematical operations.
Matlab was originally developed as a programming environment for numerical calculations and programs, whereas Mathematica was developed primarily as a tool for mathematicians to perform symbolic math and typeset their equations in a virtual notebook.
Aside: Though the MuPAD environment is distinct, one can access all of it's fuctionallity from within Matlab. See here for how to call MuPAD functions. Some examples: 1, 2, and 3.

Nope - it's how MATLAB was written. As far as I am aware, Mathematica is the only tool that uses symbolic notation for actual code.
I think a problem with having symbols instead of code is that you now need a way of writing those symbols (a menu bar, a tablet input, etc.) that would make it extremely cumbersome for a user.

Matlab is based on its diversity of toolbox, one of the toolbox support the symbolic notions you mention is the Symbolic Math Toolbox.
The Math Toolbox includes the MuPAD language. MuPAD is similar to Mathematica language, and here is a basic tutorial of MuPAD tutorial
In addition to Matlab, if you want Symbolic notation, IPython Notebook also use the actual Symbols. And it is faster, newer and easy to use.
Hope this will help you.

Related

Browse MATLAB integrated functions

I tried to find the source code for some integrated MATLAB functions. Is there any way to find MATLAB's integrated functions? For example I can't find hypot source code.
Most MATLAB functions are supplied as MATLAB source code, and you can view the source by typing edit <functionname>. Some of the lower level functions, however, are implemented in C for better performance and are built-in - you can't see the source code. hypot is one of these.
However the algorithms are not typically that secret - you can read an article about hypot (including the algorithm) on Cleve Moler's blog.

Is there a way to define a general function in matlab?

Matlab has functionalities that allow you to work with known functions that you must define.
But, sometimes I want to do a complex symbolic calculation using a general function, Say A(x), without specifying A(x).
In other words, is it possible for me to make a statement like
diff(A(x^2+1),x), where the answer should involve a symbolic derivative of A???
diff(A(x^2+1),x) = A' diff(x^2+1,x)
That is, if A' is the derivative of A.
Yes. The functionality you describe is part of the symbolic algebra toolkit -- note that it comes with some fairly significant limitations, but, in short, all you would require would be
syms x A(x)
diff(A(x), x)
Note that ' is reserved for transpose, even with symbolic functions. (Although, personally, I'd frankly suggest Mathematica for any serious symbolic algebra any day over matlab -- it's really the intended purpose of the whole product, whereas the symbolic algebra toolkit is exactly that: a toolkit add-on to the core features of Matlab, namely fast linear algebra).

Diagonalization hermitian matrices julia vs fortran

I have a program written in Fortran and in Julia, one of the cases I have symmetric matrices
and I get results more or less similar with both programs. When I switch to a case where I have hermitian matrices, the program in Julia and the program in Fortran give me different stuff. I would guess that maybe the difference comes from the diagonalization procedure, in Fortran I use:
ZHEEVD(..)
while in Julia I simply use:
eig(matrix)
The first thing that I notice is that ZHEEVD fixes the first row of the eigenvector matrices to real numbers (no imaginary part), while eig fixes the last row to real numbers.
Any idea how to overcome this tiny differences? Any more info that can be useful when dealing with julia's linear algebra built-ins?
Digging in to the Julia methods (the #less macro is very handy for this), you'll find that it eventually calls the LAPACK.syevr! method, which in the Complex128 case is a wrapper for the ZHEEVR LAPACK method (scroll down a bit to see the actual definition).
If you'd prefer to keep using ZHEEVD, you can access it via the ccall interface: see the manual section on Calling C and Fortran code. The LAPACK wrappers linked above should provide plenty of examples (LAPACK comes as part of OpenBLAS, which is included in Julia, so you shouldn't need to install anything else).

How do I use built-in MATLAB functions?

MATLAB has lots of built-in functions that I can call, such as "sin" and "norm." However, some of MATLAB's built-in functions are part of different libraries that I cannot access directly. For example, the function "ssim" is part of MATLAB's image processing toolbox, so I cannot simply call "ssim" in my code and have it work.
How do I call built-in MATLAB functions that are in different libraries? Do I need to import the libraries somehow? If so, how do I do that? How do I do this for ssim specifically?
Thanks so much!
Type ver into the command window to see which toolboxes belong to the license you bought.
Any function of these installed toolboxes you can call normally, like the mentioned sin.
Sometimes, if you're lucky, you can find equivalent functions of otherwise expensive toolboxes at MATLAB File Exchange.

Using a MATLAB code on Scilab

Is it possible to use a MATLAB code on Scilab? Is that what is meant when saying that Scilab is a "clone" from MATLAB?
There is a tool to automatically convert Matlab source to Scilab source, it's called M2SCI. A script parses the Matlab source code and replaces Matlab-specific functions by Scilab ones. See the documentation of the mfile2sci function.
Yes you can use MATLAB code on scilab. See these links for more information:
http://help.scilab.org/docs/5.4.0/fr_FR/section_36184e52ee88ad558380be4e92d3de21.html
http://help.scilab.org/docs/5.4.0/en_US/index.html
I would not bet on it. But if your code is simple enough chances are good.
Problems are:
There is encrypted p-code in Matlab that Scilab will not be able to open.
Matlab usually comes with a number of toolboxes that might not be available to you (i think especially Simulink)
last but not least (i don't know about scilab) there usually are minute differences in how functions are implemented.
There are a number of projects out there trying to replicate/replace MATLAB:
Julia language: which has a relatively similar syntax to MATLAB and offers great performance, but still lacks a lot of toolboxes/libraries, as well as not having a GUI like MATLAB. I think this has the brightest future among all MATLAB alternatives.
Python language and its libraries NumPy and matplotlib: which is the most used alternative. I think at this moment the community is a couple of orders of magnitude even bigger than MATLAB. Python is the de facto standard in machine learning and data science at the moment. But still, the syntax and memory concept is a bit far from what people are used to in the MATLAB ecosystem. There are also no equivalent to SIMULINK, although Spyder and Jupyter projects have come a long way in terms of the development environment.
Octave: is basically a clone of MATLAB to a point they consider any incompatibility as a bug. If you have a long MATLAB code that you don't want to touch, this is the safest bet. But again no alternative for SIMULINK.
SciLab and it's fork ScicoLab are the best alternatives in terms of GUI, having a SIMULINK replica xcos / scicos and a graphical user interface development features. However the community is not as big as Octave and the syntax is not completely compatible. Sadly the Scilab development team has gone through a devastating family crisis leading to the software falling behind.
Honorary mention of Modelica language implementations OpenModelica and jModelica for being a superior alternative to SIMULINK-SimScape. You should know that you can load Modelica scrips also in xcos and scicos. If you want to kno wmore about JModelica you may see this post.
you may check the MATLAB's Alternativeto page to see more Free and Open source alternatives.