MAKING SUBJECT OF FOMULAR

HOW DO I MAKE X SUBJECT OF FOMULAR IN THIS EQUATION x = exp(x+y).
I have tried the following code
syms x y
solve('x = exp(x+y)',x)
and this give me *
[sym empty].*
How best can I do it.

1 Comment

I am also stoked with a situation of the same form. All out gigs should please look into this kind of problem and suggest a way out.

Sign in to comment.

Answers (2)

In older versions of MATLAB,
solve('x = exp(x+y)', 'x')
In more modern versions
syms x y
solve(x == exp(x+y), x)
However, MATLAB is not able to find a solution. A solution exists, and is
-lambertw(-exp(y))
but MATLAB is not strong on Lambert W processing.

1 Comment

Chibuzo Chukwu comments to me
Your contribution has been very useful

Sign in to comment.

Chibuzo Chukwu
Chibuzo Chukwu on 13 Dec 2018
Thanks for your response. I have tried to read about the Lambert W function and it has been helpful but can you look at this problem?
There are series of values for x and a and it's required to have a linear plot of a against x in the equation connecting them
ln(x^alpha * a) = c- 2*x*m
To determine values alpha and m from the graph
Is there anyway this can be rearrange to achieve this?

15 Comments

I am not clear as to what the inputs are, and what is to be determined? Is the task to fit scalars c and m given inputs x, alpha, and a ?
I forgot to add that c is just a constant which I have litle or no interest on. However, its not known as well.
John D'Errico
John D'Errico on 13 Dec 2018
Edited: John D'Errico on 13 Dec 2018
Please stop adding answers. Moved from an answer to a comment.
"The inputs are x and a and the parameters to determine are m and alpha"
Anyway, this is a completely different question. Askit as a new question, rather than resurrecting an old question into a zombie question.
Are x and a restricted to positive ?
Please pardon my use of the forum. I so new here. x and a are all positive numbers
First approximations, which can be used in fitting:
alpha = ((-x2+x3)*ln(a1)+(x1-x3)*ln(a2)-ln(a3)*(x1-x2))/((x2-x3)*ln(x1)+(-x1+x3)*ln(x2)+ln(x3)*(x1-x2))
c = ((x2*ln(a3)-ln(a2)*x3)*ln(x1)+(-x1*ln(a3)+ln(a1)*x3)*ln(x2)+ln(x3)*(ln(a2)*x1-x2*ln(a1)))/((x2-x3)*ln(x1)+(-x1+x3)*ln(x2)+ln(x3)*(x1-x2))
m = ((-ln(a2)+ln(a3))*ln(x1)+(ln(a1)-ln(a3))*ln(x2)-ln(x3)*(ln(a1)-ln(a2)))/((2*x2-2*x3)*ln(x1)+(-2*x1+2*x3)*ln(x2)+2*ln(x3)*(x1-x2))
If you calculate sum of squared residues (log(x^alpha * a) -( c- 2*x*m))^2 for a number of x and a, then you can use standard calculus techniques: differentiate ssr for m, solve that for m, substitute into ssr, differentiate with respect to alpha, solve for alpha: then there appear to be patterns for m and alpha that you could probably write formulae for with a bit of study: it looks like there are probably accessible analytical optima. However, these will be in terms of c, and solving for c analytically appears to be too messy by the time you get to 5 terms.
Perhaps a hybrid approach then: construct the sum of squared residues, use calculus to find optimal m and alpha in terms of c, and then do a numeric minimization to find the optimal c, after which you can back-construct alpha and then m.
I wish to contact you directly. Probably, I will need to send you the data set which in some cases can be more than 60 rows for a and m.
60 rows can easily be attached here as a .mat or xlsx file.
I have attached the data. The goal is to get a single value of alpha and m
The column heading of the file implies that the second column is Ln(a) rather than a itself. I will assume that is true.
T = readtable('Spectrum.xls'); %xlsread 'basic' does not support Unicode
x = T{:,1};
Ln_a = T{:,2};
syms alpha m c real
ssr = sum( (alpha*log(x) + Ln_a - (c + 2 * x * m)).^2 );
sol_m = simplify(solve(diff(ssr, m), m));
ssr_m = simplify(subs(ssr, m, sol_m));
sol_alpha = simplify(solve(diff(ssr_m, alpha), alpha));
ssr_m_alpha = simplify(subs(ssr_m, alpha, sol_alpha));
best_c = simplify(solve(diff(ssr_m_alpha,c),c));
best_alpha = simplify( subs(sol_alpha, c, best_c) );
best_m = simplify( subs(subs(sol_m, c, best_c), alpha, best_alpha) );
Each of those best_* variables is a rational value. You will probably want to double() them to get floating point approximations.
>> double([best_alpha, best_c, best_m])
ans =
1.03482316989617 6.11693587912047 0.000599853145856567
Thanks for your response and the wanderful piece of code to what I asked. To be honest, your code addressed my initial question but it seems its not exactly what I need.
My purpose is to find the value of alpha and m for which when Ln_a is plotted against x it gives a straight line (or linear graph). Looking at the equation you will observe that its a power equation but I'm interested on at the top left end of the graph of Ln_a Vs x gives a linear graph.
I only hope I have communicated my intentions well. Thanks alot so far
? Ln_a and x are inputs. If you plot Ln_a against x you will get whatever you get, regardless of alpha and m values.
Chibuzo Chukwu
Chibuzo Chukwu on 17 Dec 2018
Edited: Chibuzo Chukwu on 17 Dec 2018
Yes, your observations are correct. What I am saying is, say there are two points p1 and p2 of the line that meets this conditions (ie the linear part of the graph of the plot of Ln_a aginst x). Then can the code be designed to only perform this solution for this range (ie between p1 and p2) of data other than the entire data as you did before?
No. If part of your data has a linear fit then it makes no sense to fit a power model to it.
If you want a linear fit then set alpha to 0. That would get ln a on the left side and linear terms on the right leading to aa simple polynomial fit.
Thanks a lot. Your insight has been very useful and infact you've answered my question very satisfactory. I will get back to you if I find any other obstacle. Thanks a million.

Sign in to comment.

Asked:

on 20 Sep 2014

Commented:

on 17 Dec 2018

Community Treasure Hunt

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

Start Hunting!