Need help solving first order DiffyQ analytically with matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eva Carrillo
el 10 de Dic. de 2019
Editada: Ridwan Alam
el 10 de Dic. de 2019
I'm given the equation
. This can also be written as
. Where
where
and
is a 2x1 matrix with initial value of
. I need to solve this problem analytically with Euler method, I've already solved it numerically. I need to plot time vs. intensity.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253730/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253731/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253732/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253733/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253734/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253735/image.png)
my code attempt is as follows:
gamma=0.5;
H=[(gamma*i) -1;-1 -i*gamma];
G=(2:2);
psi=(2:1);
psi(1,1)=1;
psi(2,1)=0;
T=10;
N=1000;
deltat=T/N;
x=[];
y=[];
t=[];
x(1)=0.5;
y(1)=0;
t(1)=0;
t1=[];
for t=1:N
t1(end+1)=t;
x(t+1)=x(t)+y(t)*deltat;
y(t+1)=y(t)+deltat*(-i*H*psi);
intensity=abs(y).^2;
int1(end+1)=intensity(1,1);
int2(end+1)=intensity(2,1);
end
plot (t1,int1,'-*');
hold on;
plot (t1,int2,'-*');
hold off;
I keep getting the error 'Unable to perform assignment because the left and right sides
have a different number of elements.' for line 36: y(n+1)=n*y(n)+deltat*(-i*H*psi);
I am very confused by this and could use the help!
2 comentarios
Chuguang Pan
el 10 de Dic. de 2019
The right n*y(n)+delta*(-i*H*psi) is 2x1 matrix, but left y(n+1) is scalar!
Respuesta aceptada
Ridwan Alam
el 10 de Dic. de 2019
Editada: Ridwan Alam
el 10 de Dic. de 2019
If I understood it right, your x and y are supposed to be 2x1 vectors.
gamma=0.5;
H=[(gamma*i) -1;-1 -i*gamma];
% G=(2:2); % where is it used?
psi=zeros(2,1);
psi(1)=1;
psi(2)=0;
T=10;
N=1000;
deltat=T/N;
x1=0.5;
y1=0;
t=0;
x=[x1; x1];
y=[y1; y1];
t1=[]; int1 = []; int2 = [];
for t=1:N
t1(end+1)=t;
x(:,t+1)=x(:,t)+y(:,t)*deltat;
y(:,t+1)=y(:,t)+deltat*(-i*H*psi);
intensity=abs(y(:,t+1)).^2;
int1(end+1)=intensity(1);
int2(end+1)=intensity(2);
end
plot (t1,int1,'-*');
hold on;
plot (t1,int2,'-*');
hold off;
Hope this helps!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Special Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!