Info
此问题已关闭。 请重新打开它进行编辑或回答。
Is there a function I can use to find out when a statement is true?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm new to matlab.
Is there a function I can use to find out when a statement is true?
Simple example: for which "x" the equation is true.
1+x = 3
Can somebody help me?
Alex
0 个评论
回答(2 个)
Sulaymon Eshkabilov
2020-4-23
in your case, if ... else ... end structure should work very well.
0 个评论
Ameer Hamza
2020-4-23
编辑:Ameer Hamza
2020-4-23
See this. It uses symbolic toolbox to solve the equations.
syms x
eq = 1+x == 3;
sol = solve(eq);
Result:
>> sol
sol =
2
See documentation of solve() function for more examples.
3 个评论
Karan Mehta
2020-4-23
Hi Alexander
Can you please share the error message when you solve this equation. Also, in order to solve 1/(10^x * (10^x+1)), represent this in form of an equation ,eg. 1/(10^x*(10^x+1)) == "some value". Then it would work. Like i tried the following
>> syms z
>> eq = 1/(10^z * (10^z + 1)) == 10
eq =
1/(10^z*(10^z + 1)) == 10
>> sol = solve(eq)
sol =
log(- 35^(1/2)/10 - 1/2)/log(10)
log(35^(1/2)/10 - 1/2)/log(10)
Ameer Hamza
2020-4-23
I got the same answer as Karan. But if you are using release older than R2020a, than it is possible that MATLAB didn't return a solution. It seems that MATLAB has made some improvements to the symbolic engine in the new release, and it is able to solve equations that were not possible before. In that case, you will need to rely on a numerical solution
eq = @(x) 1/(10^x*(10^x+1)) - 10;
sol = fsolve(eq, rand);
The downside is that it can only give one solution at a time.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!