Info
This question is closed. Reopen it to edit or answer.
Is there a function I can use to find out when a statement is true?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Sulaymon Eshkabilov
on 23 Apr 2020
in your case, if ... else ... end structure should work very well.
0 Comments
Ameer Hamza
on 23 Apr 2020
Edited: Ameer Hamza
on 23 Apr 2020
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 Comments
Karan Mehta
on 23 Apr 2020
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
on 23 Apr 2020
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.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!