# how to find inverse

조회 수: 219(최근 30일)
Sabri Kenno 2019년 10월 16일
답변: Walter Roberson 2019년 10월 16일
hi. I have a question. how can I solve this: if f(x)=x^2/1+sqrt x how can i find finvese(2)?
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Dimitris Kalogiros 2019년 10월 16일
Which exactly is your function f(x) ?
Is it the following ?
f(x)=(x^2) / ( 1+sqrt(x) )
And are you trying to solve the equation y=f_inverse(2) ?

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

### 답변(3개)

Sabri Kenno 2019년 10월 16일
yes its followig:
If f(x)=x^2/(1+sgrtx) find finverse(2) corect to 5 decimal places
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Dimitris Kalogiros 2019년 10월 16일
편집: Dimitris Kalogiros 2019년 10월 16일
Generally, you must have in mind that :
Taking that under consideration you can use the following piece of code
clear; clc;
syms x
% definition of f(x)
f(x)=(x^2) / (1+sqrt(x))
% f(x) is an increasing function of x
fplot(f(x), [0, 3]);
grid on; xlabel('x'); ylabel('f(x)')
% find x0, where f(x0)=2
x0=vpasolve(f(x)==2)
% x0 is the wanted value, since 2=f(x0) <=> finv(2)=x0
% === verification of our solution ===
%find inverse function
finv(x) = finverse(f);
% calculation of finv(2)
x0_verification=vpa(finv(2))
If you don't aim to use symbolic toolbox, you can use simple matlab instructions in order to calculate value x0:
clear; clc;
f=@(x) (x^2)/(1+sqrt(x));
y0=2;
%initial guess for finverse(y0)
x0=0;
%initialization for iterations
yerror=f(x0)-y0;
yerror_previous=yerror;
dx=0.1;
%loop for finding x0
while abs(yerror)>1E-5
% we have cross over y0, step must become less
if yerror*yerror_previous<0
dx=0.1*dx;
end
%store current error for next iteration
yerror_previous=yerror;
%adjust x0
x0=x0-sign(yerror)*dx;
yerror=f(x0)-y0;
end
fprintf(' finverse(2)= x0 = %f \n', x0);
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Walter Roberson 2019년 10월 16일
target_value = 2;
inverse_for_target = fzero(@(x) f(x)-target_value, initial_guess);

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

### Community Treasure Hunt

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

Start Hunting!

Translated by