i want to find the transpose of the matrix m but showing error. please can anyone help with the error

6 views (last 30 days)
function [m]=calc_m()
m_rot()=@(w) [0;cos(w);sin(w)];
Q=[0.4082,0.4082,-0.8165;0.7017,-0.7071,0;0.5774,0.5774,0.5774];
m()=@(w) Q*m_rot();
z=m.'

Accepted Answer

Geoff Hayes
Geoff Hayes on 20 Mar 2019
Edited: Geoff Hayes on 20 Mar 2019
sadgun - can't you just do
z=m';
without the period? Though I'm not sure why you are setting this result to z since your function output parameter is m. Perhaps the above line of code should just be
m=m';
or the function signature should change to indicate that z is the output parameter.
Though perhaps this isn't the error? When I try to run your code, the first error is
m_rot()=@(w) [0;cos(w);sin(w)];
|
Error: An indexing expression on the left side of an assignment must have at least one
subscript.
Remove the brackets so that the assignment is just
m_rot = @(w) [0;cos(w);sin(w)];
The assignment for m will have the same problem so that should probably be
m = Q * m_rot(w);
where w is some value. Remember that m_rot is a function handle and so requires an input. Is this even correct though? Do you expect m to be a 3x1 matrix or should it be a rotated 3x3 matrix? Please clarify.
  9 Comments
sadgun pulagam
sadgun pulagam on 21 Mar 2019
c11=169.9, c12=122.6, c44=76.2
these are the only inputs required i hope. other all are given inside the code itself.
Walter Roberson
Walter Roberson on 24 Mar 2019
Your calc_m_n returns function handles for m and n.
Then on line 33 you have
mat_uv(i,j)=mat_uv(i,j)+z(k)*mat_C(k,i,j,l,c11,c12,c44)*m(@(w)(l));
This calls the function handle m, passing in a function handle @(w) (l) . That is a function handle that, if executed, would accept any input and return the current value of l (lower-case L) as of the time the anonymous function was created.
The function handle that was returned for m involves Qinv and taking its parameter (w) and applying a matrix rotation to it by way of m_rot . That involves taking the cos() of the argument. But the argument is the function handle @(w)(l) and you cannot take the cos of a function handle.
It is not at all obvious why you use @(w)(l) as the argument to m on line 33, since on the next line, line 34, where you invoke the very similar n, you just pass in l instead of an anonymous function that encapsulates l like you do for m

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!