Clear Filters
Clear Filters

Error: Invalid expression log equation

2 views (last 30 days)
I am trying to solve an equation in Matlab mobile.
Following is the code -
syms t a
eqns =-a*log((3*t/4)*(3-t^2)/(2-t))-(1-a)*log((1/t^2)*((3-2*t)/(2-t)))+a*((1-t)^2)*(3-t)/((2-t)*(3-t^2)-(1-a)*(1+t)/(3-2*t))*((t*(-18+21*t-7*t^3+2*t^4)*(log((3-2*t)*(3-t^2)/(2*t(2-t)^2))))/(36-39*t+13*t^3-4*t^4+a*(-18+27*t-18*t^2+5*t^3)))+2*log((1/3)*(3-t^2)/(2-t))+t*log((4*(t^3)/27)*((3-t^2)/(3-2*t)))-2*t==0;
But I keep getting the error
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Apr 2021
syms t a
eqns =-a*log((3*t/4)*(3-t^2)/(2-t))-(1-a)*log((1/t^2)*((3-2*t)/(2-t)))+a*((1-t)^2)*(3-t)/((2-t)*(3-t^2)-(1-a)*(1+t)/(3-2*t))*((t*(-18+21*t-7*t^3+2*t^4)*(log((3-2*t)*(3-t^2)/(2*t(2-t)^2))))/(36-39*t+13*t^3-4*t^4+a*(-18+27*t-18*t^2+5*t^3)))+2*log((1/3)*(3-t^2)/(2-t))+t*log((4*(t^3)/27)*((3-t^2)/(3-2*t)))-2*t==0;
Error using sym/subsindex (line 864)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.

Error in sym/subsref (line 909)
R_tilde = builtin('subsref',L_tilde,Idx);
% 12 1 2 1 2 10 1 0 12 1 23 2 3 210 12 1 0 1 0 12 1 2 1 2 1 2 1 2 10 12 3 2 3 45 4 5 4 5 6 5 4321 2 3 210 12 1 2 1 2 10 12 3 2 1 23 2 3 210
The bracket count is okay, it all balances out, and the error message you indicate does not occur. A different error occurs instead.
Have a look at the place the bracket count reaches 6:
% (2*t(2-t)^2)
% 5 6 5 4
Notice that you are trying to index t by 2-t . That is an error. You probably want (2*t*(2-t)^2)
  15 Comments
Tomas
Tomas on 2 May 2023
the U in this case is a random variable. So, should I just change it to a different random variable to clear that issue?
Walter Roberson
Walter Roberson on 2 May 2023
f_inv = @(x) log(-2*(2-x))
This will be complex-valued unless x >= 2.
It is not at all clear why you do not instead write
f_inv = @(x) log(2*(x-2))

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!