[SOLVED] CS matlab fprintf( -n );

$25

File Name: CS_matlab_fprintf(_-n_);.zip
File Size: 226.08 KB

5/5 - (1 vote)

fprintf( –
);
fprintf( Q 1
);
fprintf( –
);

fprintf( Q 1.1
);

M_scale = [ 3 0; 0 2 ];
fprintf( Scaling:
)
% Transpose just to fix matlab printing
fprintf( %5.2f %5.2f
, M_scale );
fprintf(

)

fprintf( Q 1.2
);

H_x = [ 1 2; 0 1 ];
fprintf( Shear x:
)
fprintf( %5.2f %5.2f
, H_x );
H_y = [ 1 0; 2 1 ];
fprintf( Shear y:
)
fprintf( %5.2f %5.2f
, H_y );
fprintf(

)
fprintf( Shear x/y (symmetric but non-unit diagonal):
)
fprintf( %5.2f %5.2f
, (H_y*H_x) );
fprintf(

)

fprintf( Q 1.3
);

delta = -90/180*pi;
R_90 = [ cos(delta) -sin(delta); sin(delta) cos(delta) ];
fprintf( Rotation -90:
)
fprintf( %5.2f %5.2f
, R_90 );
fprintf(

)
clear all;

fprintf( –
);
fprintf( Q 2
);
fprintf( –
);
M_trans = [ 1 0 -1; 0 1 2; 0 0 1 ];

M_scale = [ 3 0 0; 0 2 0; 0 0 1 ];
fprintf( Scaling then translation (homogenous):
)
fprintf( %5.2f %5.2f %5.2f
, (M_trans * M_scale) );
fprintf(

)

H_x = [ 1 2 0; 0 1 0; 0 0 1];
fprintf( Shear x then translation (homogenous):
)
fprintf( %5.2f %5.2f %5.2f
, (M_trans*H_x) );
H_y = [ 1 0 0; 2 1 0; 0 0 1 ];
fprintf( Shear y then translation (homogenous):
)
fprintf( %5.2f %5.2f %5.2f
, (M_trans*H_y) );
fprintf(

)
fprintf( Shear x/y then translation (homogenous):
)
fprintf( %5.2f %5.2f %5.2f
, (M_trans*H_y*H_x) );
fprintf(

)

delta = -90/180*pi;
R_90 = [ cos(delta) -sin(delta) 0; sin(delta) cos(delta) 0; 0 0 1];
fprintf( Rotation -90 then translation (homogenous):
)
fprintf( %5.2f %5.2f %5.2f
, (M_trans*R_90) );
fprintf(

)
clear all;

fprintf( –
);
fprintf( Q 3
);
fprintf( –
);

M = [ sqrt(2)3*sqrt(2);
-sqrt(2)3*sqrt(2) ];
[U,S,V] = svd(M);
fprintf( U:
)
fprintf( %5.2f %5.2f
, U );
fprintf(
)
fprintf( S:
)
fprintf( %5.2f %5.2f
, S );
fprintf(
)
fprintf( V^T:
)
fprintf( %5.2f %5.2f
, V );
fprintf(
)
fprintf( Verify that M=USV^T:
)
fprintf( %5.2f %5.2f
, (U*S*transpose(V) M) );
fprintf( –
);
fprintf(
)

A = M*transpose(M);
fprintf( A (symmetric matrix):
)
fprintf( %5.2f %5.2f
, A*A);
fprintf(
)

[R,D] = eig( A );
fprintf( R (eigendecomposition):
)
fprintf( %5.2f %5.2f
, R);
fprintf( D (eigendecomposition):
)
fprintf( %5.2f %5.2f
, D);

fprintf( Verify that A=RDR^T:
)
fprintf( %5.2f %5.2f
, (R*D*transpose(R) A) );
fprintf(

)
clear all;

fprintf( –
);
fprintf( Q 4
);
fprintf( –
);

p = [ 2 -1 -5 1 ];
t0 = [ sqrt(2)/2 -sqrt(2)/2 0 0 ];
t1 = [ 0 0 -1 0 ];
n = [ sqrt(2)/2 sqrt(2)/2 0 0 ];

Sx2 = [ 2 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1 ];
Rx90 = [ 1 0 0 0; 0 0 -1 0; 0 1 0 0; 0 0 0 1];
Ty1 = [ 1 0 0 0; 0 1 0 1; 0 0 1 0; 0 0 0 1];

Tall = Ty1 * Rx90 * Sx2;

pH = Tall * p;
pCartesian = pH(1:3)/pH(1); % not necessary here

fprintf( Transformed p
)
fprintf( [ %5.2f %5.2f %5.2f ]^T
, pCartesian );
fprintf(
)

nH = transpose(inv(Tall))*n;

nCartesian = nH(1:3); % direction do not divide by 0!
fprintf( Transformed n
)
fprintf( [ %5.2f %5.2f %5.2f ]^T
, nCartesian );
fprintf(
)

fprintf( Verify normal is normal to tangent plane. Before: %5.2f %5.2f
,
dot(n,t0),dot(n,t1));
fprintf(
)

fprintf( [Verify normal is still normal to the transformed tangent plane:
%5.2f %5.2f
], dot(transpose(inv(Tall))*n, Tall * t0),
dot(transpose(inv(Tall))*n, Tall * t1))
fprintf(
)
clear all;

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS matlab fprintf( -n );
$25