Matlab Symbolic toolbox question, 'exp' and vector elements

In summary: This method allows you to use the "sym" function and still have a specific value for a particular element in your vector. In summary, to use the symbolic math toolbox with a specific element of a vector, use the "subs" function to substitute the element into your expression.
  • #1
shalehound117
3
0
I have a piece of code which near its end needs to do the following task: Given a vector V=(log(A),log(B),log(C)) that has been previously generated[I've used 'log' as opposed to ln here because the 'log' function in MATLAB is the natural logarithm], I need to find sum(A,B,C). NOT sum(log(A),log(B),log(C))=log(A*B*C), but sum(A,B,C). However, log(A),log(B) and log(C) are each large negative numbers (log(A)=-6126.9,log(B)=-4371.2,log(C)=-2942.1) When I use exp the results are rounded to zero. This is a problem, because the next step in the code is log(D), where D=sum(A,B,C), and log(0)=-Inf (I have a good reason for going from log to exp and back again). I can use the symbolic math toolbox to get the precision I need so that the results for using 'exp' are very small numbers instead of being rounded to 0. However, I don't know how to put this inside my code, i.e. when I type k=sym('exp(v(1,1))') in the MATLAB command window, it returns k=exp(v(1,1)) as opposed to the value 1.3217180682567377112866860751447*10^(-2661), which is what I get when I do k=sym('exp(-6126.9)'). How can I use sym('exp()') with a particular element of a vector so that I can put this in my code? I'm new to matlab, and if part of the problem is I'm trying to use a tool without understanding how it works, well, learning is exactly why I am at this forum. Thank you very much to anyone who has any advice.
 
Physics news on Phys.org
  • #2
The best way to use the symbolic math toolbox with a particular element of a vector is to use the "subs" function. This allows you to substitute an expression for a variable. For example, if you have a vector V=(log(A),log(B),log(C)) and you want to calculate exp(V(1,1)), you could use the following code:k = sym('exp(x)');k = subs(k, 'x', V(1,1));This would return k=exp(v(1,1)) with the corresponding value 1.3217180682567377112866860751447*10^(-2661).
 

1. What is the purpose of the Matlab Symbolic toolbox?

The Matlab Symbolic toolbox is a collection of functions and tools that allow users to perform symbolic computations, such as algebraic manipulations, calculus, and solving equations with symbolic variables. It is particularly useful for mathematical and engineering applications.

2. What does the 'exp' function do in Matlab Symbolic toolbox?

The 'exp' function in Matlab Symbolic toolbox is used to compute the exponential of a symbolic expression or variable. It is equivalent to the mathematical constant e raised to the power of the input argument.

3. How can I use the 'exp' function to manipulate vector elements in Matlab Symbolic toolbox?

In order to use the 'exp' function to manipulate vector elements, you can first use the 'syms' function to define the vector as a symbolic variable. Then, you can use the 'subs' function to substitute the vector elements with the desired values and evaluate the 'exp' function on the resulting expression.

4. Can the 'exp' function be used on non-numeric inputs in Matlab Symbolic toolbox?

Yes, the 'exp' function can be used on non-numeric inputs in Matlab Symbolic toolbox, such as symbolic variables or expressions. However, it is important to note that the input must be a valid mathematical expression in order for the function to produce a meaningful result.

5. Is the 'exp' function in Matlab Symbolic toolbox equivalent to the 'exp' function in Matlab's regular toolbox?

Yes, the 'exp' function in Matlab Symbolic toolbox is equivalent to the 'exp' function in Matlab's regular toolbox. Both functions compute the exponential function, but the difference is that the 'exp' function in the Symbolic toolbox can handle symbolic inputs and expressions, while the regular 'exp' function can only handle numeric inputs.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
565
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top