Search code examples
matlabexponential

How to neglect an exponential function containing a variable in MATLAB?


I am writing a code for some physics problem. I want to simply neglect the terms containing the variable 't' and make my matrix independent of time 't'.

syms t real
syms temp  
i=sqrt(-1);  
temp=[exp(t*2*i)*exp(-t*5*i) + 12 exp(3*t*i); exp(-3*t*i) exp(-t*2*i)*exp(t*5*i)+8];

what i expect in my out put is

temp= [12 0;0 8];

I am unable to do it. Can any one help me to solve this ? Thanks in advance.


Solution

  • A couple of comments:

    1. i is already supported as the imaginary number in MATLAB. It is superfluous to declare i = sqrt(-1);. Also real is a function in MATLAB. It basically returns the real part of a complex number defined in MATLAB. Do not make this symbolic. By doing this, you would be shadowing over the function with that variable name.

    2. Don't do syms temp. You are making this variable symbolic, yet you are overwriting its behaviour in the last line of code.


    Now, what you mean by "neglect" is to have any values that have t in the expression go to 0. There really isn't an easy way to do this. There's no utility in MATLAB (at least to my knowledge), that can pick through all mathematical expressions in an array or matrix where if there are terms that have a t in it, you should set them to 0.

    The only thing I can suggest is if you substitute t = 0, then subtract 1 from all of the elements. This is because when you substitute t = 0 into each expression in your matrix, exp(0) = 1, and so all elements will have a common 1 term due to each expression having an exponential term. Therefore:

    out = subs(temp, 't', 0) - 1;
    
    out =
    
    [ 12, 0]
    [  0, 8]