What is actually symbolic variable in matlab? - matlab

I am new in learning matlab. when I am using the solve() function, matlab warning me that i must use a symbolic variable before using the solve function. but I actually don't know what the sym variable is. or What is the difference between the symbolic variables and the ordinary variables of the base workspace?

Symbolic variables are useful to express equations and manipulate them in an analytic manner. You can use them to manipulte them algebrically, without the need of actually associating any type of numbers.
Suppose you want the exact analytical form of a solution for an equation, in terms of symbols that express this function. Then you can use a sym variable to express and operate with the unkwons, rather than to use on numerical methods to find solutions
Symbolic variables are also useful to operate with tranfer funcions and perform simplications that are very tedious If done without a computer program.
You also can associate numbers with sym variables, once you have done all the all the intended operations.
If you don't want perform operations with algebraic variables, you should checkout the fsolve function

Related

multi-variable optimization in matlab?

I need to minimize a function that involves two variables. The problem is that this function is not directly related to those two variables. Many other variables are to be calculated first, which are actually functions of the first two variables, and then they're used to calculate the function. And I can't put the function and the two variables in one equation. So, what options do I have in matlab to solve this optimization problem?
Thanks

Are Syms and Symsum slow?

Im working on a huge matlab code in which I have a symbolic function G as well as its inverse invG and first derivative g defined using "syms" and I use "matlabFunction" in certain functions. These symbolic functions are called multiple times within various functions in the code. The problem is that my code is toooo slow and I suspect the symbolic functions are to blame.
Im also using "symsum" for some convergent series and sums.

Solve equation without using symbolic toolbox in Matlab

I need to solve this equation for the variable \theta:
using Matlab WITHOUT using symbolic toolbox. The reason for this is that I am compiling the m-file to .Net Assembly and symbolic toolbox can not be used.
I know how to solve it using vpasolve, but as far as I know it needs the variable to be defined using syms.
I appreciate if you can suggest me a method to solve this equation in Matlab without symbolic toolbox.
As #rayryeng said, that is only possible if you know the value of the other variables, is so, you can declare f as an anonymous function and use fsolve() like this:
f=#(x)((cos(x)*sqrt(2^2+3^2)-4*sin(x))/(cos(x)-1)-5/x);
fsolve(f,0.1)
but using your correct values.

Converting Matlab anonymous functions to Scilab inline functions

Most of my Matlab functions can be converted with the mfile2sci function to Scilab functions except some functions that contain anonymous functions (for example f=#(x,y)sin(x)+log(y)). Is there a way to convert the anonymous functions to Scilab inline functions (for example, for the previous example deff('[z]=f(x,y)','z=sin(x)+log(y)')) so that I don't have to change my Matlab functions?
Yes, in its current state the Matlab to Scilab translator mfile2sci fails to translate anonymous functions, but this behavior can be improved by the following patch:
https://codereview.scilab.org/#/c/20916/
However, be warned that anonymous function occur most of the time when using "solvers" like fsolve, optim, ode solvers (e.g. ode45, ode15s,...), and that statements using these are never translated to working Scilab statements (a warning is given).

Using symbolic variables in Simulink

How do I use symbolic variables in the Simulink block diagram for different blocks? I'd like to run linmod2 and obtain a transfer function in the terms of the symbolic variables.
According to John D'Errico, aka woodchips, this likely not possible. That was my understanding of the way the linmod family of algorithms worked as well. However, what are you trying to do that you need to get the analytic representation of the model with the symbolic parameter? There may be other ways to accomplish what you need, please elaborate.