Inverse of algebraic expression in Matlab

1 回表示 (過去 30 日間)
AVM
AVM 2020 年 2 月 16 日
回答済み: Star Strider 2020 年 2 月 17 日
I need to get inverse expression of the following algebraic expression in matlab.
clc;
clear;
syms r
E(r)= 1-1/2*((1+r)*log2(1+r)+(1-r)*log2(1-r));
g=finverse(E)
Using this command no output is there. I need to see the expression of r in terms of E. Is there any way to get that. Pl somebody help me.
output is
g(r) =
Empty sym: 0-by-1
  2 件のコメント
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 2 月 16 日
The problem in your case is that matlab cannot find a close form to your inverse function, so it gives as an output a warning and the empty result, otherwise your code would give the correct result (you could interpret the "r" from g as E and g as "r"). For what reason do you want the inverse expression? If you just want the numeric values I would calculate E in the wished interval and then maybe fit a polynom for the inverse mapping.
AVM
AVM 2020 年 2 月 17 日
@Thiago: Thanks for your reply. Actually I have a function f which has explicitly r dependency but not E. And E is a fucntion of r explicitly. I need to plot that fucntion f with E , but not with r. Then how can I proceed?

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 2 月 17 日
Possibly:
rfcn = @(E) fsolve(@(r) 1-1/2*((1+r).*log2(1+r)+(1-r).*log2(1-r)) - E, 10); % Anonymous Function: r(E)
N = 200;
Ev = linspace(0, 1, N); % Sample E’ Vector
for k = 1:numel(Ev)
r(k) = rfcn(Ev(k));
end
figure
plot(Ev, real(r), Ev, imag(r))
grid
gama = linspace(-1, 1, N);
[Gama,Rm] = ndgrid(gama,r);
G = @(r,gama) atan(r.*tan(N*gama)); %% r is [0,1];
g = @(r,gama) atan(r.*tan(gama)); %% gama is also [-1,1];
Delta=G(Rm,Gama)-N*g(Rm,Gama);
figure
meshc(gama, Ev, real(Delta))
grid on
xlabel('\gamma')
ylabel('E')
zlabel('\Delta')
view(125,25)
and:

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 2 月 16 日
編集済み: John D'Errico 2020 年 2 月 16 日
As is often the case, not all simple problems have an algebraic solution. In fact, as you have found, it is trivial to write one where that fails.
However, it is also easy to solve numerically, as long as you have some value that you wish to solve for. If you plot it, you will see the relation is symmetric around the y axis.
fplot(E,[-2,2])
As well, it has singularities at -1 and 1, and does not exceed 1, nor does it have real values for r outside of the open interval (-1,1). That should be clear just by inspection.
pretty(E)
log(1 - r) (r - 1) log(r + 1) (r + 1)
------------------ - ------------------ + 1
2 log(2) 2 log(2)
Since you are using a symbolic form, just use vpasolve.
vpasolve(E(r) == 0.5,r,.5)
ans =
0.77994427112328089747637659133002
See that I chose a start point greater than zero, so vpasolve found a positive solution.
I could also have used fzero, of course.
  5 件のコメント
John D'Errico
John D'Errico 2020 年 2 月 17 日
I'm sorry, but I will not keep chasing a moving target. This question is going far afield in the comments, morphing from one problem to another. I solved your first two questions, but I cannot play the role of long term MATLAB consultant to solve your every problem. If I did, then you will just return with another modified form with an extra variable ot two, but where you are not thinking for yourself.
I'll just suggest that if you think of it along the lines of how I showed you how to solve the first two problems, it will be clear.
AVM
AVM 2020 年 2 月 17 日
Thanks for you reply. Okay, I am trying as you said.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by