I have three vectors A, B, and C. For each value in these vectors I would like to solve the equation C^x = A^x + B^x. Unfortunately this is an equation that I have found to be solvable only iteratively, so I am attempting to use MATLAB’s “solve” function to find a solution for each case. My code is as follows:
exponents = zeros(100,1);
syms x
A = rand(100,1);
B = rand(100,1);
C = rand(100,1);
for i = 1:100
exponents(i) = eval(solve(C(i)^x == A(i)^x + B(i)^x));
end
Sometimes, however, the solution is unobtainable, which leads to the error message, “Warning: Explicit solution could not be found.” I am okay with this, but if I run into an unsolvable equation, I would like to simply leave the “exponents(i)” unchanged for that iteration and move onto the next one, instead of having my code abruptly stop. Any suggestions?
If you put the statement that causes the occasional error inside a try/catch statement, then the error will not cause execution to stop. For example, you could try: