Can someone help me to draw a function having the Bolzano-Weierstrass property?

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Andrew Newell
Andrew Newell il 27 Giu 2011
Can a single function have the BZ property? I thought it applied to sets of points or functions.
Munteanu Alexandru
Munteanu Alexandru il 28 Giu 2011
Bolzano’s theorem
If a function f(x) is continuous on a closed interval [a,b] and f(a) and f(b) are of different sign, there exists at least a point c between a and b such that f(c)=0.
i was thinking to make a function like myfucntion(thefunction,interval1,interval2) and inside to make a linspace from interval1 to interval2 and a polyval of thefunction and my intervals. after that to plot the result into something. but i don't know exactly how to do it.
thanks

Accedi per commentare.

Risposte (2)

Matt Dunham
Matt Dunham il 2 Lug 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
Floris il 29 Giu 2011
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 Commento
Munteanu Alexandru
Munteanu Alexandru il 3 Lug 2011
I had to do for all possible functions. And I hat to find first if the intervals had different sings and the function is continuous. And plot the functions between those intervals, and on the results to show in how many points (f(c)) equals 0.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by