Can someone help me to draw a function having the Bolzano-Weierstrass property?
Afficher commentaires plus anciens
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 commentaires
Andrew Newell
le 27 Juin 2011
Can a single function have the BZ property? I thought it applied to sets of points or functions.
Munteanu Alexandru
le 28 Juin 2011
Réponses (2)
Matt Dunham
le 2 Juil 2011
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
Floris
le 29 Juin 2011
0 votes
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?
1 commentaire
Munteanu Alexandru
le 3 Juil 2011
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!