solving equation for one unkown

3 views (last 30 days)
Ahmed Nabil
Ahmed Nabil on 21 Sep 2017
Edited: John D'Errico on 22 Sep 2017
Hi, I'm trying to solve the following equation which 'eps' is unknown
(Uz60==U_star/k*log((Z2/Zo)-eps)
I know it can be simplified by putting 'eps' in either side alone, but I have much more complicated equations and tryin' to understand the function required to solve it.
syms eps
[eq1]=(Uz60==U_star/k*log((Z2/Zo)-eps));
epsilon=solve([eq1],eps);
Which most variables are matrices (109x1)
at the workspace 'eq1' is 109x1 matrix but 'eps & epsilon' are empty matrcies 1x1
or am I using the wrong function?
  4 Comments
Pal Szabo
Pal Szabo on 21 Sep 2017
minimal working example, I guess
Rik
Rik on 22 Sep 2017
Indeed I mean minimal working example. (quote from Wikipedia:)
"In computing, a minimal working example (abbreviated MWE) is a collection of source code and other data files which allow a bug or problem to be demonstrated and reproduced. The important feature of a minimal working example is that it is as small and as simple as possible, such that it is just sufficient to demonstrate the problem, but without any additional complexity or dependencies which will make resolution harder."
We currently can't run your code, which makes your problem difficult to reproduce.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 22 Sep 2017
Edited: John D'Errico on 22 Sep 2017
By the way, it is a really bad idea to use eps as a variable. eps already exists in MATLAB, as a function that is quite useful. By using that name as a variable, you interfere with the working of the function eps.
I do know that changing the variable name for eps won't fix the problem here of course, which is that you really apparently have 109 distinct problems.
However, what you are trying is doomed to fail as it is, since by trying to solve for ONE value of eps, MATLAB tried to solve for the unique value of that variable which solves ALL of them at once. There is some logic in that presumption, since you did effectively give it 109 equations, with one unknown. Since there is obviously no single value that solves all of the 109 instances you want to solve, solve will give up.
The solution is of course trivial. USE A LOOP. Just solve the problem 109 times, once for each problem instance. Save the results from each solve into a vector of length 109. (Preallocate the results, don't try to grow the vector as it is built.) Yes, you can (with some effort) write code that will get solve to work on the entire set of subproblems. No, there is no gain. In fact, it will probably run more slowly than just using a loop.

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!