MATLAB: How to create this function

functioniterationy=x

I need help writing a function that will carry out the following:
y(x) = Bj*Cj(x)*aj
where Cj = diag[exp(im*k*x),exp(-im*k*x)]
Bj and aj are not dependent on x
How can I write code for this in MATLAB?

Best Answer

I did this for you, I hope it serves you.
% Definition of constants:
k=2;
Bj=[1 2; 3 4]; %In this case Bj is a matrix of size 2x2,
%of real numbers,you can modify this.

aj=[1; 1]; %In this case aj is a vectorof size 2x1,
%of real numbers,you can modify this.
%This is the definition of your function:
Y=@(x)(Bj*diag([exp(k*x(1)*1i),exp(-k*x(2)*1i)])*aj);
%To test, if x is a constant, define the vector only with
% that constant(expl: x = 5, so here you define x = [5 5]); if x is
%a vector of variables, you define it as it is here in the code:
x=[1 2];
Y=Y(x);
disp(Y) %Check the value in Command Window.
Related Question