Wrong solution using solve with a logarithmic

4 ビュー (過去 30 日間)
Matthew Worker
Matthew Worker 2021 年 6 月 24 日
回答済み: Walter Roberson 2021 年 6 月 25 日
Hello,
I wanted to solve an equation containing a log function. The solution given by Matlab is not correct, until I multiply the logarithm by 10.
I'm aware of the difference between log and log10 and want to use the natural logarithm.
f_1 = 10* (eta_p/(b_pstern * g * eps_min))*(log(W_0/(W_0-B1)))== s*1000 ;
W_K_1 = double(solve(f_1, B1))
In the equation, everything is numeric except for B1. When I type the exact same equation into my calculator, I get the correct answer. The "10*" is the correction factor I use for the "correct" solution.
Am I using the log function wrong or is there some other error?
  2 件のコメント
dpb
dpb 2021 年 6 月 24 日
Would have to have a complete test case including constants to do any diagnositics...
Matthew Worker
Matthew Worker 2021 年 6 月 25 日
編集済み: N/A 2021 年 6 月 25 日
Thank you for your response. The code with all the variables would be as following :
syms B1
f_1 = (6314642578216891*log(-35316/(B1 - 35316)))/536870912 == 300000 % With *10
f_2 = (5051714062573513*log(-35316/(B1 - 35316)))/4294967296 == 300000 % Without *10
ans = double(solve(f_1, B1))
ans2 = double(solve(f_2, B1))
f_1 is the corrected formula, as it offers the correct solution. f_2 is the formula that I need to use, but f_2 outputs the wrong solution. If I type f_2 into my calculator, I get the solution that Matlab outputs for f_1.
I hope you can follow my explanation!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 25 日
The outputs cross-check properly
format long g
syms B1
f_1 = (6314642578216891*log(-35316/(B1 - 35316)))/536870912 == 300000 % With *10
f_1 = 
f_2 = (5051714062573513*log(-35316/(B1 - 35316)))/4294967296 == 300000 % Without *10
f_2 = 
f1_sol = solve(f_1)
f1_sol = 
f2_sol = solve(f_2)
f2_sol = 
double(f1_sol)
ans =
889.379424789019
subs(f_1, B1, f1_sol)
ans = 
lhs(ans)-rhs(ans)
ans = 
0
double(f2_sol)
ans =
7950.69092580946
subs(f_2, B1, f2_sol)
ans = 
lhs(ans)-rhs(ans)
ans = 
0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by