# Tema 12
12-2  Equacions diferencials 
          ordinàries d'ordre 1.
          Sistemes.

## EDO de variables separades

kill(all)$

Exemple 12.2.1

EDO_vs1: 2*diff(y(t),t) - y(t) = 0;

ode2(EDO_vs1, y(t), t);

ic1(%, t=0, y(0)=100);

ic1( y(t)=%c*%e^(t/2) , t=0, y(0)=100);

y(t):=100*%e^(t/2)$     
wxplot2d([y(t)], [t, 0, 5], [ylabel, ""]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

Exemple 12.2.2

kill(all)$

EDO_vs2:diff(y(x),x)=2*(100-y(x));

ode2(EDO_vs2, y(x), x);

expand(%);

ic1( % , x=0, y(0)=50);

expand(%);

y(x):=100-50*%e^(-2*x)$     
wxplot2d([y(x)], [x,0, 3],   [ylabel, ""]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

## EDO Lineals

Exemple 12.2.3

kill(all)$

EDO_lin1:   t^2 - y(t) = t * diff(y(t), t) ;

ode2(EDO_lin1, y(t), t);

expand(%);

ic1(y(t)=t^2/3+%c/t, t=1, y(1)=5);

expand(%);

y(t):=t^2/3+14/(3*t)$     
wxplot2d([y(t)], [t, 1, 10],  [ylabel, ""]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

## EDO de Bernouilli

Exemple 12.2.4

kill(all)$

EDO_ber1:  diff(y(t), t) + 2*t*y(t) + t*y(t)^4=0;

ode2(EDO_ber1, y(t), t);

logcontract(%);

log((y(t)^3 + 2)/(y(t)^3))=3*t^2+C1;

((y(t)^3+2)/y(t)^3)=exp(C1+3*t^2);

eq1:  (y(t)^3+2)/y(t)^3=%e^(C1+3*t^2)$
solve(eq1, y(t));

y(t):=2^(1/3)/(%e^(C1+3*t^2)-1)^(1/3);

y(0);

eq2:   y(0)=1;
solve(eq2, C1);

yp(t):=2^(1/3)/(%e^(log(3)+3*t^2)-1)^(1/3);

wxplot2d([yp(t)], [t, 0, 3],  [ylabel, ""]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

## EDO de Ricatti

Exemple 12.2.5

kill(all)$

EDO_ric1: t*(t-1)*diff(y(t), t) - (1-2*t)*y(t) + y(t)^2 = 2*t;

ode2(EDO_ric1, y(t), t);

y(t):=1+1/u(t);

diff(y(t), t);

EDO_ric2: t*(t-1)*(-'diff(u(t),t,1)/u(t)^2) - (1-2*t)*y(t) + y(t)^2 = 2*t;

ratsimp(%);

EDO_ric3:  (t^2-t)*('diff(u(t),t,1)) + (-2*t-1)*u(t) - 1 = 0;

ode2(EDO_ric3, u(t), t);

factor(3*t^3-9*t^2+9*t-3);

u(t):=C*(t-1)^3/t - 1/(3*t);

y(t):=1 + 1/u(t);

'y(t)=y(t);

ratsimp(%);

y(t):=(3*C*(t-1)^3 +3*t - 1 ) / (3*C*(t-1)^3  - 1);

eq5:  y(2)=2;
solve(eq5, C);

yp(t):=(3*(7/3)*(t-1)^3+3*t-1)/(3*(7/3)*(t-1)^3-1);

wxplot2d([yp(t)], [t, 2, 5],  [ylabel, ""]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

## Sistemes d'EDO d'ordre 1

kill(all)$

Exemple 12.2.6

EDO_1a: 'diff(x(t), t)  - x(t) +  'diff(y(t), t) = 2*t + 1;
EDO_1b: 2*'diff(x(t), t) + x(t) + 2*'diff(y(t), t)  = t ;

desolve(  [EDO_1a, EDO_1b]  , [x(t), y(t)] );

atvalue(x(t), t=0, -2/3);
atvalue(y(t), t=0, 1);

desolve(  [EDO_1a, EDO_1b]  , [x(t), y(t)] );

x(t):=-t-2/3$  y(t):=t^2/2+(4*t)/3+1$
wxplot2d([x(t), y(t)], [t, 0, 10],   [legend, "x(t)" , "y(t)"]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$

Exemple 12.2.7

kill(all)$

EDO_2a: 'diff(x(t), t)  -    3*x(t) + 2* 'diff(y(t), t) + 4*y(t)= 2*sin(t) ;
EDO_2b: 2*'diff(x(t), t) + 2*x(t) +     'diff(y(t), t)  - y(t)   = t          ;

desolve(  [EDO_2a, EDO_2b]  , [x(t), y(t)] );

atvalue(x(t), t=0, 2);
atvalue(y(t), t=0, 3);

desolve(  [EDO_2a, EDO_2b]  , [x(t), y(t)] );

x(t):= -(7*sin(t))/65-(9*cos(t))/65+(166*%e^(-t/3))/35-(1011*%e^(-5*t))/2275+(4*t)/5-54/25     $  
y(t):=  (18*sin(t))/65-(14*cos(t))/65+(166*%e^(-t/3))/35+(1348*%e^(-5*t))/2275+(3*t)/5-53/25 $

wxplot2d([x(t), y(t)], [t, 0, 10],     [legend, "x(t)" , "y(t)"]   , [style, [lines, 2]] ,
[gnuplot_preamble, "set size ratio 1; set grid;"]  , [nticks, 100] )$