Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Solving Coupled ODE's by ODE45

3 views (last 30 days)
Ömer Yaman
Ömer Yaman on 19 Oct 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
Dear all,
I have a coupled ODE with two functions. One of them is a gaussian beam. I do want to solve the other one. So far to understand how ode45 works I wrote down such a code which is given below.
gamma = (1e+9)/3
omega = (1e+9)/3
[t,y] = ode45(@(t,y) arbit2(t,y,gamma,omega), [0 20e-9],[0 1]);
plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of coupled ode with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
function dydt = arbit2(t,y, gamma, omega)
dydt = [(-gamma-omega)*y(1)+(omega)*y(2); (gamma+omega)*y(1)+(-omega)*y(2)];
end
My question is how can I modify y(1) as a function. For example I want to write a function that gives y(1) as following;
t = 0:1e-15:1e-12;
a=3
y = a*gaussmf(t,[0.5e-13 5e-13]);
I want to solve y(2) according to given y(1) Thanks in advance.

Answers (2)

Star Strider
Star Strider on 19 Oct 2018
If I understand correctly what you want, you can simply modify ‘arbit’ (and calls to it) directly:
arbit2 = @(t,y, gamma, omega,a) [a*gaussmf(t,[0.5e-13 5e-13]); (gamma+omega)*y(1)+(-omega)*y(2)];
gamma = (1e+9)/3
omega = (1e+9)/3
a = 3;
tv = 0:1e-15:1e-12;
[t,y] = ode45(@(t,y) arbit2(t,y,gamma,omega,a), tv,[0 1]);
plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of coupled ode with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
It is not an interesting result.
  4 Comments
Ömer Yaman
Ömer Yaman on 19 Oct 2018
Actually I'm trying to solve that.
x'(t)=[(-a-b)*x(t)]+[b*y(t)] y'(t)=[(a+b)*x(t)]+[-b*y(t)]
x(t)= gaussian. I want to solve y(t)
Star Strider
Star Strider on 19 Oct 2018
I have no idea what
x(t)= gaussian
implies, or what ‘a’ and ‘b’ are.
Try this:
arbit2 = @(t,z,a,b) [(-a-b).*(exp(-(a-z(1)).^2/b)) + b.*z(2); (a+b).*(exp(-(a-z(1)).^2/b))+(-b-z(2))];

Torsten
Torsten on 19 Oct 2018
function dydt = arbit2(t,y, gamma, omega)
a=3;
y_fix=a*gaussmf(t,[0.5e-13 5e-13]);
dydt = [(-gamma-omega)*y_fix+(omega)*y(2); (gamma+omega)*y_fix+(-omega)*y(2)];
end
  1 Comment
Ömer Yaman
Ömer Yaman on 19 Oct 2018
if I set a=0, it gives still y(1) result. how?

This question is closed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!