# [Matlab] Non-Linear Differential Equations

Page 1 of 1

## 3 Replies - 681 Views - Last Post: 24 July 2013 - 06:54 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=325463&amp;s=2840b68f198ee951b8afc808ed51c42f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 TurboST2

Reputation: 0
• Posts: 37
• Joined: 11-November 11

# [Matlab] Non-Linear Differential Equations

Posted 23 July 2013 - 09:43 AM

Ok, I need some help getting this code to work properly. I've exhausted all my know-how and got as far as I could. I'm going to post a link to my assignment as opposed to typing it all out and just paste what code I've come up with so far.

Here is the link to the theory. This is where the equations I'll be using are defined. (EQ-1 and EQ-2) I'll also post an image of the equations so you don't have to really go to this page if you don't want.

Here is the actual assignment.

ok, so I know I need two functions for each differential equation. Here are the functions I wrote:

Function 1: (For Part 1)
```function [THWdot] = dsysEQ1(t,THW)

g=9.8;
l=10;

% x -->TH
% y -->W
x=THW(1,1);
y=THW(2,1);

xdot=y*(t);
ydot=(-g/l)*sind(x*(t));

THWdot(1,1)=xdot;
THWdot(2,1)=ydot;
end
```

Function 2: (For Part 2)
```function [THWdot] = dsysEQ2(t,THW)

g=9.8;
l=10;

% x -->W
% y -->TH
x=THW(1,1);
y=THW(2,1);

A=[0,1;(-g/l),0];
B=[y;x];

THWdot=A*THW+B;
end

```

Here is my script. I haven't been able to get it to work for the first function and haven't begun writing script to utilize the other function or for labeling plots and such. I don't need help with plotting and if I can get some help writing script that makes the first function work, I should be able to finish the rest of it from there.

```tSPAN=[0,60];
IC1=[0.25;0];
IC2=[1.50;0];

[t,THW]=ode45(@dsysEQ1,tSPAN,IC1);

plot(t,THW)
axis([0,60,-1,1])

```

Thank you for any help offered.

Is This A Good Question/Topic? 0

## Replies To: [Matlab] Non-Linear Differential Equations

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12318
• Posts: 45,417
• Joined: 27-December 08

## Re: [Matlab] Non-Linear Differential Equations

Posted 23 July 2013 - 10:04 AM

How doesn't it work? What specific problems or errors are you encountering?

### #3 TurboST2

Reputation: 0
• Posts: 37
• Joined: 11-November 11

## Re: [Matlab] Non-Linear Differential Equations

Posted 23 July 2013 - 10:09 AM

Running it in the current state outputs:

The output should look like:

Only without the linearized solultion. So I should only be seeing a blue sin wave that doesn't increase/decrease frequency. Currently I'm outputting two sin waves that are increasing in frequency. Something I'm doing isn't right.

### #4 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

## Re: [Matlab] Non-Linear Differential Equations

Posted 24 July 2013 - 06:54 PM

Hi, I think that theta will be in radians so you wont use sind.