Can someone help me to draw a function having the Bolzano-Weierstrass property?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello
I have a project about continuous function. And I have to write a code in Matlab that draws the a function with Bolzano-Weierstrass property?
Can someone explain me how to do it? Or a little piece of code that can help me?
Thank you very much, Alex
PS Sorry for my bad English.
댓글 수: 2
Andrew Newell
2011년 6월 27일
Can a single function have the BZ property? I thought it applied to sets of points or functions.
답변 (2개)
Matt Dunham
2011년 7월 2일
function y = weierstrass(x, a, b, n)
%%The Weierstrass function
% This is an example of a function which is everywhere continuous, but
% nowhere differentiable.
%
%
%%INPUTS
% x - a scalar or vector
% b - [7] an odd integer
% a - [0.82] a double between 0 and 1
%
% such that a*b > 1 + 1.5*pi
%
% n - [~300] summation limit, (in the true function this is inf) but here
% you must
% pick a finite value for the approximation. If you pick too large a
% value, you'll get NANs since b^n can easily exceed realmax. By
% default, the largest possible n is chosen.
%
% See http://en.wikipedia.org/wiki/Weierstrass_function
%
%%OUTPUT
% y - same dimensions as x, (the output of the function)
%
If no inputs are given, this line is called: plot(-2:0.005:2, weierstrass(-2:0.005:2, 0.82, 7, 363));
%%Matt Dunham (July 2, 2011)
if nargin < 2, a = 0.82; end
if nargin < 3, b = 7; end
if nargin < 4, n = floor(log(realmax)/log(b)) - 1; end
if nargin < 1
plot(-2:0.002:2, weierstrass(-2:0.002:2));
return
end
assert(mod(b, 2) > 0); % b must be odd
assert(a > 0 && a < 1);
assert((a*b) > (1 + 1.5*pi));
y = sum(bsxfun(@times, a.^(0:n), cos(pi*bsxfun(@times, b.^(0:n), x(:)))), 2);
end
댓글 수: 0
Floris
2011년 6월 29일
If it can be any function you have to plot, just make a linear one?
say: x1 = a, y1 = f(a), x2 = b, y2 = f(b), with (as given) f(a) and f(b) a different sign. Then just make the line y=M*x+C through the points (x1,y1) and (x2,y2). There is going to be a point c for which f(c)=0. It can even be easily found analytically.
Or do I misunderstand your problem?
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!