Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying create a function that returns a matrix containing a variable "l" which is an independent variable to be swept for a plot later on.

I would calculate "phi" based on user inputs which include "n" and "d", then I would use "n", "d", and "phi" to find "a", "b", "c", and "d" to create a matrix "m" with. This matrix "m" will be a function of "l".

phi = 2*pi*n*d/l;
a = cos(phi);
b = 1i*sin(phi)/n;
c = 1i*n*sin(phi);
d = cos(phi);
m = [a b;c d];

I'm really not enjoying Matlab's coding style as compared to C++ and Python... How would you guys implement this functionality?

Summary: I want a function that returns a matrix which contains an independent variable to be swept for a plot later.

share|improve this question
    
This question may be better suited for stackoverflow. –  Michael Ulm Feb 4 '11 at 7:57
    
Okay, I'll try over there. –  user6605 Feb 4 '11 at 16:41

1 Answer 1

Just to clearing out of the unanswered list!

You can define either a handle with @ or you can wrap up what you did as a function simply by

function [ mout ] = m_of_l( lin )
phi = 2*pi*n*d/lin ;
mout = [cos(phi) 1i*sin(phi)/n;1i*n*sin(phi) cos(phi)];
end

Later, you can use M = m_of_l(2*pi) to evaluate it at $l=2\pi$.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.