Can someone help me to draw a function having the Bolzano-Weierstrass property?
5 次查看(过去 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!