Error: Invalid expression log equation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.
채택된 답변
Walter Roberson
2021년 4월 17일
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.
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
Sabrina Garland
2021년 4월 17일
편집: Sabrina Garland
2021년 4월 17일
Thanks @Walter. It helped!
I wrote this for solution but i got the following error -
Warning: Solutions are parameterized by the symbols: [z, z1, z2], z1, z2. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'. > In sym/solve>warnIfParams (line 475) In sym/solve (line 357) Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'. > In sym/solve>warnIfParams (line 478) In sym/solve (line 357)
Is there a problem with following syntax?
Soln1= solve(eqn, t, a)
And how can fix domain for t and a between 0 and 1 for solution?
Thanks!
In theory....
syms t a real
assumeAlso(t >= 0 & t <= 1)
assumeAlso(a >= 0 & a <= 1)
eqn =-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;
Soln1 = solve(eqn, t, a, 'returnconditions', true, 'maxdegree', 3)
Soln1.a
Soln1.t
Soln1.conditions
In practice, this is going to take a long time to compute, and the answers are probably going to be difficult to understand.
I will see if I can figure out anything more useful.
Numerically, solutions include ones near
[
[0.80814734211076188233189764141161, 0.014157347318462409368745988278694]
[0.81774556051925063803415290145514, 0.017065493529859707439482572850095]
[0.82046261258401125142952904134027, 0.017914365002905370826371367553424]
[0.83165113247410330040663713139042, 0.021511344137270273069885390156103]
[0.86235181325356451804474711062975, 0.032006454691267775967023011531556]
[0.87728607400691739688823315300636, 0.037335270904563136299631940445499]
[0.89107163976355238503111378722198, 0.04233730158150518105730901834881]
[0.89922319441534142597544034193216, 0.045323008878958357652554141689136]
[0.92700631525224144351158031340986, 0.055600120484060467263409966499192]
[0.93050016660009881345983008776409, 0.056899680092455104708862984031671]
[0.94723947876611726467967480882978, 0.063136374364404389516159540203479]
[0.99119633032880843853815771634112, 0.079505614940861258639688187409334]
]
It is worth checking the accuracy of some of those: for example are the 2nd and 3rd really the same solution, or are they distinct solutions?
The computation took about 3/4 of an hour and produced 33 possible solutions. Now I am seeing if I can make any sense out of the conditions.
Thank you so much! That was of great help. It solved my problem!!! I am not sure if i can thank you enough.
Walter Roberson
2021년 4월 17일
편집: Walter Roberson
2021년 4월 17일
So... take
syms t a real
eqn =-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;
fsurf(eqn, [0 1 0 1]);
view(3)

As you look closer in to this, it turns out that are there are an infinite number of solutions along a curved line. The limits are at approximately t < 0.1 and a > 0.7 and that otherwise you should be able to find a solution. For example,
t1 = 0.0123;
eqn1 = subs(eqn, t, t1)
eqn1 =

a1 = vpasolve(eqn1)
a1 =

@Walter Sorry to disturb you again but I keep getting solution in parameters. Why is that?
Soln1 =
struct with fields:
t: [1×1 sym]
a: [1×1 sym]
parameters: [1×2 sym]
conditions: [1×1 sym]
Solution for a is coming out to be z1. Why?
I demonstrated above that the solution is not a point or finite set of points, but is instead a line. As such, if MATLAB is going to be able to produce an answer at all, it would have to parameterize the line in some variable, and say "t has this relationship to the parameter, and a has this other relationship to the parameter."
For example:
syms x y real
sol = solve(x^2 + y^2 == 4, [x, y], 'returnconditions', true)
sol = struct with fields:
x: [2×1 sym]
y: [2×1 sym]
parameters: [1×1 sym]
conditions: [2×1 sym]
sol.x
ans =

sol.y
ans =
sol.conditions
ans =
MATLAB had to parameterize the solution because there are an infinite number of solutions.
Oh! Thanks at Walter! Then how did you get the vector of numerical solutions that you printed? (I am new to Matlab and don't know the exact syntax for this).
I used vpasolve with different random starting points, rand(2,1) and threw away results that did not meet the constraints.
Okay! Thanks again!!!
I'm also getting a similar errror in a code that I am trying to write. I have tried writing the equation in about three or four different ways and I'm still getting the same error. The expression and error are shown below.Again this is just one of the forms that I've tried for the equation. I've tried -1.*log(2-2u) and -log(2-2u). Any help is appreciated!
f_inv = @x log(-2(2-u))
f_inv = @x log(-2(2-u))
↑
Invalid expression. Check for missing multiplication operator,
missing or unbalanced delimiters, or other syntax error. To
construct matrices, use brackets instead of parentheses.
-2(2-u)
There is absolutely no where in MATLAB that supports implicit multiplication. -2(2-u) as far as MATLAB is concerned, is unary minus applied to the result of indexing the number 2 by the index 2-u -- which is an error because literals cannot be subscripted in MATLAB.
Tomas
2023년 5월 2일
the U in this case is a random variable. So, should I just change it to a different random variable to clear that issue?
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))
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 F Distribution에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
