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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by