Quantcast
Channel: MATLAB Central Newsreader - tag:"quantum"
Viewing all articles
Browse latest Browse all 2

Re: Need help with anonymous functions in a matrix

$
0
0
On 10/30/14, 5:25 AM, Adrian wrote:
> I have a matrix that i'm using to solve a system of equations [4x4][1x4] with some symbolic values.
>
> eg. Ax = b (where A is 4x4 and x and b are 1x4)
>
> Next I want to take the first and last value of my resulting [1x4] matrix and find the complex conjugates of those values.
>
> say x [1x4] = [a;b;c;d]
>
> and i need [a*;b*;c*;d*]
>
> Next i need to take a* and d* and calculate the equation T = (d*)*d/(a*)*a
>
> This however produces a symbolic version of my original matrix and i need to do calculations with real values. Most values i can set to 1 however i need to have one value range over a set of values so i can plot T vs this value.

So, you put in symbolic parameters, and expect real-valued results?
Sure, I'd expect T to be real based on your formula. I don't see where
it is not.

> Here is my symbolic representation.

Unfortunately, I don't see the connection between your description and
your code. To boot, your code does not contain any x, a, b, c, d, or T.

> I then tried using (with L = 1)
> q = @(E) sqrt(2*(E-1));
> k = @(E) sqrt(2*E);
> and
> E = linspace(1,2*pi,100);
>
> but this doesn't seem to work.

What do you mean by that? What output would qualify as “works”?

If you want to replace some “q” in a symbolic expression such as T1, it
doesn't help to set the MATLAB variable q to some value, and the E in
your definition of q will not pick up a MATLAB variable E, either.
Here's something that should “work,” in some useful sense of the word:

E = linspace(1,2*pi,100);
Tf = matlabFunction(T1, 'vars', [q, k, C, L]);
Tvals = Tf(sqrt(2*(E-1)), sqrt(2*E), 1, 1);
plot(E, Tvals)


> % % E = linspace(1,2*pi,100);

> and the error i received
>
> ??? Error using ==> vertcat
> CAT arguments dimensions are not
> consistent.
>
> Error in ==> Qntm_ASSN3 at 47
> matA1 = [1 1 -1 0 ; k1(E)./q1(E)
> -k1(E)/q1(E) 1 0 ; 0 0 -exp3 exp4 ; 0
> 0 exp3 k1(E)/q1(E).*exp4];

Your first row has four entries. The second row starts with
k1(E)./q1(E), which has 100 entries. That simply cannot work, since
matrices are supposed to be rectangular.


HTH,

Christopher

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images