Hot to do the math for plotting ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Hot to do the math for plotting ?

OppaErich
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
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Hot to do the math for plotting ?

Doug Stewart-4


On Tue, Jan 16, 2018 at 10:50 AM, Stephan Goldenberg <[hidden email]> 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
[hidden email]
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");



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Hot to do the math for plotting ?

OppaErich
In reply to this post by OppaErich
Hi,

for some reason Thunderbird doesn't offer a "Reply-List" option with
Doug Stewart's post.


The plots look fine. So, it looks like I have translated the math into
Octave syntax correctly. The problem is that this is an exercise for an
edX course which asks to plot all three functions in one plot.

Regards,
Stephan

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Hot to do the math for plotting ?

OppaErich
On 20.01.2018 13:57, Stephan Goldenberg wrote:

> The plots look fine. So, it looks like I have translated the math into
> Octave syntax correctly. The problem is that this is an exercise for an
> edX course which asks to plot all three functions in one plot.

Replying to myself...

Mr Stewart's post induced an idea and this solved the problem.

plot(x,F,'x',x,G,'*',x,H,'o');

was plot(x,F,'x',G,'*',H,'o');

Plot looks fine now, problem solved.

Thanks and have a nice weekend all,
Stephan

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