I'm writing a function which takes a 3x3 matrix as input and gives an angle and a position vector as output.Position vector has 3 more output arguements. Please help me identify the mistake i have made.
Show older comments
Code, I have written the function code:
function [ double(theta1), double(kx), double(ky), double(kz)] = equi_axis_angle( var11, var12, var13; var21, var22, var23; var31, var32, var33 )
theta1 = acos((var11 + var22 + var33 - 1) * 0.5);
kx = (var32 - var23)*0.5/sin(theta1);
ky = (var13 - var31)*0.5/sin(theta1);
kz = (var21 - var12)*0.5/sin(theta1);
end
When I run the code I get:
Error: File: equi_axis_angle.m Line: 1 Column: 18
Unbalanced or unexpected parenthesis or bracket.
Pls see var11, var12...are matrix elements.
Accepted Answer
More Answers (2)
I have no idea what you're trying to accomplish with your function declaration. The double() in the output list and the ; in the input list make absolutely no sense.
function [output_list] = function_name(input_list)
where output_list and input_list is a list of variable names only separated by commas only.
Possibly you meant:
function [theta1, kx, ky, kz] = equi_axis_angle(var11, var12, var13, var21, var22, var23, var31, var32, var33)
Or possibly you meant to pass the input as a single matrix instead of a gazillion input variables, in which case:
function [theta1, kx, ky, kz] = equi_axis_angle(some_meaningful_name) %replace some_meaningful_name by something that actually has meaning. Not var!
theta1 = acos((some_meaningful_name(1,1) + some_meaningful_name((2,2) + some_meaningful_name(3,3) - 1) * 0.5);
kx = (some_meaningful_name(3,2) - some_meaningful_name(2,3))*0.5/sin(theta1);
ky = (some_meaningful_name(1,3) - some_meaningful_name(3,1))*0.5/sin(theta1);
kz = (some_meaningful_name(2,1) - some_meaningful_name(1,2))*0.5/sin(theta1);
end
Andrei Bobrov
on 2 Oct 2015
function [th, kxz] = equi_axis_angle(var)
th = acos((trace(var)-1)*.5);
k = var - var.';
k = k(tril(ones(3),-1)>0).*[1;-1;1];
kxz = k*.5/sin(th);
1 Comment
Jai Khullar
on 2 Oct 2015
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!