Error: Invalid expression log equation
2 views (last 30 days)
Show older comments
Sabrina Garland
on 17 Apr 2021
Commented: Walter Roberson
on 2 May 2023
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.
0 Comments
Accepted Answer
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;
% 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
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
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))
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!