# Why am I obtaining incorrect values for Lipschitz 1/2 norms using the central difference method?

조회 수: 4 (최근 30일)
Dylan Holloway . 2022년 12월 22일
편집: Jan . 2023년 1월 7일
The Lipschitz 1/2 norm is defined as the maximum value of the absolute value of the derivative of the function over all points in the domain of the function. I have this code that can approximate this value for a given function:
% Define the function f
f = @(x) x.^2;
% Define the domain of the function
x = linspace(-1, 1, 1000);
% Compute the derivative of the function using the central difference method
df = (f(x+1e-8) - f(x-1e-8)) / (2*1e-8);
% Compute the Lipschitz 1/2 norm of the function
lipschitz_norm = max(abs(df));
Here, our function f and linspace for x are just an example.
I am trying to compute the norm for f = @(x) 2*sqrt(1-x), with x = linspace(0, 1, 1000). Or really, f = @(x) c*sqrt(1-x), where c is a real number. Theoretically, it's obvious that the norm for any of these functions is |c|, for a given c. Online, using this code with the example
f = @(x) 2*sqrt(1-x), with x = linspace(0, 1, 1000) gives lipschitz_norm = 2, as it should, but when I run the exact same code on MATLAB on my own, I get 1.4142e+04. I've tried numerous different examples, and my answers have yet to line up. Is there something going on on my end?
##### 댓글 수: 1없음 표시없음 숨기기
Jan 2022년 12월 22일
편집: Jan 님. 2022년 12월 22일
I cannot confirm your statement, that Matlab online calculates 2 as output:
f = @(x) 2*sqrt(1 - x);
x = linspace(0, 1, 1000);
df = (f(x + 1e-8) - f(x - 1e-8)) / 2e-8;
lipschitz_norm = max(abs(df))
lipschitz_norm = 1.4142e+04
df(end)
ans = -1.0000e+04 + 1.0000e+04i

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

### 답변 (2개)

Bjorn Gustavsson 2022년 12월 22일
You've forgot to take the derivative of the function on-line, and you seem to take some kind of derivative on your own computer. Since the derivative of sqrt(1-x) is 1/2./sqrt(1-x) the max of the absolute goes towards infinity as x aproaches 1 from below.
(Don't worrt, we've all been there)
HTH
##### 댓글 수: 0이전 댓글 -1개 표시이전 댓글 -1개 숨기기

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

Bora Eryilmaz 2022년 12월 22일
Unless I misunderstodd something, the derivative of is .
Within the domain of [0,1], the maximum absolute value of this is +Inf, not 2.
##### 댓글 수: 2이전 댓글 1개 표시이전 댓글 1개 숨기기
Bora Eryilmaz 2023년 1월 3일
"...maximum absolute value..." cannot be negative.

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

### 카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

R2022a

### Community Treasure Hunt

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

Start Hunting!