- #1
Marin
- 193
- 0
Hi all!
I am having great trouble in the last days trying to make MATLAB plot for me a function of a matrix exponential of a variable t.
Here's my attempt:
first, I define the z-Pauli matrix s_3 and the identity matrix I by:
%define the pauli matrices and the identity I%
I = [1 0; 0 1];
s_1 = [0 1; 1 0];
s_2 = [0 -1i; 1i 0];
s_3 = [1 0; 0 -1];
Then I want to plot the (real part) of both components of the vector-valued function
x = (expm(cos(t).*I + 1i.*cos(t).*s_3) )*[1;2]
using the commands:
t = 0:0.1:10;
x = (expm(cos(t).*I + 1i.*cos(t).*s_3) )*[1;2];
plot(t,x(t))
Unfortunately I got the following error:
? Error using ==> mtimes
Inner matrix dimensions must agree.
I suspect that this is because t is interpreted as a vector, say 100 components, and cos(t) is taken componentwise, so that cos(t) is also a vector of the same number of components and the error occurs when this vector is multiplied by a 2 by 2 matrix from the left.
However, I'd like MATLAB to compute the matrix exponential, multiply it by the given vector, and then plug in the t, to avoid the above error.
Does anyone have any ideas on how to make this work?
I also want to use a more complicated function defined by me instead of the sin(t) in the above expression, but I guess, if I find how to do it with a simple one like sin(t), it'll work also with manually defined functions as well
PS: I'm new to MATLAB and programming and unfortunately don't have much experience with it
Thanks a lot for the help!
With regards,
marin
I am having great trouble in the last days trying to make MATLAB plot for me a function of a matrix exponential of a variable t.
Here's my attempt:
first, I define the z-Pauli matrix s_3 and the identity matrix I by:
%define the pauli matrices and the identity I%
I = [1 0; 0 1];
s_1 = [0 1; 1 0];
s_2 = [0 -1i; 1i 0];
s_3 = [1 0; 0 -1];
Then I want to plot the (real part) of both components of the vector-valued function
x = (expm(cos(t).*I + 1i.*cos(t).*s_3) )*[1;2]
using the commands:
t = 0:0.1:10;
x = (expm(cos(t).*I + 1i.*cos(t).*s_3) )*[1;2];
plot(t,x(t))
Unfortunately I got the following error:
? Error using ==> mtimes
Inner matrix dimensions must agree.
I suspect that this is because t is interpreted as a vector, say 100 components, and cos(t) is taken componentwise, so that cos(t) is also a vector of the same number of components and the error occurs when this vector is multiplied by a 2 by 2 matrix from the left.
However, I'd like MATLAB to compute the matrix exponential, multiply it by the given vector, and then plug in the t, to avoid the above error.
Does anyone have any ideas on how to make this work?
I also want to use a more complicated function defined by me instead of the sin(t) in the above expression, but I guess, if I find how to do it with a simple one like sin(t), it'll work also with manually defined functions as well
PS: I'm new to MATLAB and programming and unfortunately don't have much experience with it
Thanks a lot for the help!
With regards,
marin