help-octave
[Top][All Lists]

## Re: Hot to do the math for plotting ?

 From: Doug Stewart Subject: Re: Hot to do the math for plotting ? Date: Tue, 16 Jan 2018 12:34:47 -0500

On Tue, Jan 16, 2018 at 10:50 AM, Stephan Goldenberg wrote:
Hi,

looks like I'm not only too numb for octave but for googleing too. I get only links to the plotting documentation.

Here's the script:

%% plot_3_functions - Plots three functions with range
%% and number of points given by user.

Interval = input('Enter interval as vector [lower upper]: ');
numPoints = input('How many points to plot: ');

x = linspace(Interval(1),Interval(2),numPoints);

F = 3.*(x).^2.-2*sin(x);     % 3x^2-2sin(x)
G = sqrt(abs(x.-3));         % sqrt(|x-3|)
H = exp(-2.*x.*x);           % e^(-2x^2)

plot(x,F,'x',G,'*',H,'o');
%% axis([Interval(1) Interval(2) -2 10]);
xlim([Interval(1), Interval(2)]);
ylim([-2, 10]);
xlabel("x-axis");
ylabel("y-axis");
title("Exercise 3.3.4");
legend("3x^2-2sin(x)", "sqrt(|x|)", "e^-2x^2");
%% saveas(gca,'fonctions.pdf','pdf');

I get 3 plots and the square function looks good but the Euler and Square-root functions G and H are plain wrong (checked with gnuplot).

So what am I doing wrong here ?

Regards,
Stephan

_______________________________________________
Help-octave mailing list
https://lists.gnu.org/mailman/listinfo/help-octave

--
DAS

here is a start for you --- it still needs some fixing.

%% plot_3_functions - Plots three functions with range
%% and number of points given by user.

Interval = input('Enter interval as vector [lower upper]: ');
numPoints = input('How many points to plot: ');

x = linspace(Interval(1),Interval(2),numPoints);

F = 3.*(x).^2.-2*sin(x);     % 3x^2-2sin(x)
G = sqrt(abs(x.-3));         % sqrt(|x-3|)
H = exp(-2.*x.*x);           % e^(-2x^2)

subplot(3,1,1)
plot(x,F);
%% axis([Interval(1) Interval(2) -2 10]);
xlim([Interval(1), Interval(2)]);
#ylim([-2, 10]);
xlabel("x-axis");
ylabel("y-axis");
title("Exercise 3.3.4");
legend("3x^2-2sin(x)", "sqrt(|x|)", "e^-2x^2");
%% saveas(gca,'fonctions.pdf','pdf');2 4

subplot(3,1,2)
plot(x,G);
%% axis([Interval(1) Interval(2) -2 10]);
xlim([Interval(1), Interval(2)]);
#ylim([-2, 10]);
xlabel("x-axis");
ylabel("y-axis");
title("Exercise 3.3.4");
legend("3x^2-2sin(x)", "sqrt(|x|)", "e^-2x^2");

subplot(3,1,3)
plot(x,H);
%% axis([Interval(1) Interval(2) -2 10]);
xlim([Interval(1), Interval(2)]);
#ylim([-2, 10]);
xlabel("x-axis");
ylabel("y-axis");
title("Exercise 3.3.4");
legend("3x^2-2sin(x)", "sqrt(|x|)", "e^-2x^2");