Thread Subject: plotting

Subject: plotting

From: niko kauppinen

Date: 18 Nov, 2009 16:58:04

Message: 1 of 3

Could someone help with this problem,
I want to plot short range of my program
How I can define range of my plot ex. 500-600t

This is my program:

%pendulum.m
%This program will use pendulum2.m
t = [0 1500];
x0 = [0; 1];
options = odeset('RelTol',1e-6,'AbsTol',1e-9);
[t,x] = ode45('pendulum2',t,x0,options);

subplot(2,1,1); plot(t,x(:,1));
title('Plot of x as a function of time');
xlabel('Time'); ylabel('theta');
subplot(2,1,2); plot(x(:,1),x(:,2));
xlabel('theta'); ylabel('theta dot');

Pendulum2

function f = pendulum2 (t,x)
w = 0.85;
gamma = 0.1;
P1 = 1;
P2 = 0;
f = zeros(2,1);
f(1) = x(2);
f(2) = -gamma*x(2)-(1+P1*cos(w*t))*sin(x(1))-P2*sin(w*t)*cos(x(1));

Regards
Niko Kauppinen

Subject: plotting

From: Pekka Kumpulainen

Date: 19 Nov, 2009 12:03:19

Message: 2 of 3

"niko kauppinen" <traveller74@jippii.fi> wrote in message <he192s$5vg$1@fred.mathworks.com>...
> Could someone help with this problem,
> I want to plot short range of my program
> How I can define range of my plot ex. 500-600t
>
> This is my program:
>
> %pendulum.m
> %This program will use pendulum2.m
> t = [0 1500];
> x0 = [0; 1];
> options = odeset('RelTol',1e-6,'AbsTol',1e-9);
> [t,x] = ode45('pendulum2',t,x0,options);
>
> subplot(2,1,1); plot(t,x(:,1));
> title('Plot of x as a function of time');
> xlabel('Time'); ylabel('theta');
> subplot(2,1,2); plot(x(:,1),x(:,2));
> xlabel('theta'); ylabel('theta dot');
>
> Pendulum2
>
> function f = pendulum2 (t,x)
> w = 0.85;
> gamma = 0.1;
> P1 = 1;
> P2 = 0;
> f = zeros(2,1);
> f(1) = x(2);
> f(2) = -gamma*x(2)-(1+P1*cos(w*t))*sin(x(1))-P2*sin(w*t)*cos(x(1));
>
> Regards
> Niko Kauppinen

If you mean the time range from 500 to 600
ind = t>=500 & t<=600;
plot(t(ind),x(ind,1))
etc...

Subject: plotting

From: niko kauppinen

Date: 26 Nov, 2009 22:13:03

Message: 3 of 3

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <he3c67$4pd$1@fred.mathworks.com>...
> "niko kauppinen" <traveller74@jippii.fi> wrote in message <he192s$5vg$1@fred.mathworks.com>...
> > Could someone help with this problem,
> > I want to plot short range of my program
> > How I can define range of my plot ex. 500-600t
> >
> > This is my program:
> >
> > %pendulum.m
> > %This program will use pendulum2.m
> > t = [0 1500];
> > x0 = [0; 1];
> > options = odeset('RelTol',1e-6,'AbsTol',1e-9);
> > [t,x] = ode45('pendulum2',t,x0,options);
> >
> > subplot(2,1,1); plot(t,x(:,1));
> > title('Plot of x as a function of time');
> > xlabel('Time'); ylabel('theta');
> > subplot(2,1,2); plot(x(:,1),x(:,2));
> > xlabel('theta'); ylabel('theta dot');
> >
> > Pendulum2
> >
> > function f = pendulum2 (t,x)
> > w = 0.85;
> > gamma = 0.1;
> > P1 = 1;
> > P2 = 0;
> > f = zeros(2,1);
> > f(1) = x(2);
> > f(2) = -gamma*x(2)-(1+P1*cos(w*t))*sin(x(1))-P2*sin(w*t)*cos(x(1));
> >
> > Regards
> > Niko Kauppinen
>
> If you mean the time range from 500 to 600
> ind = t>=500 & t<=600;
> plot(t(ind),x(ind,1))
> etc...


Kiitos Pekka Toimii!!

If I want to plot increments of 2*pi how I can do that?

Thanks

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com