Siksha 'O' Anusandhan
(Deemed To Be University)
Institute of Technical Education and
Research
RAHUL R NAIR 1
Student Name: Experiment No:
Registration No: 2241014013 Date of Experiment:
Branch (Section): ECE/35 Date of Submission:
Experiment 1:
Perform coordinate transformation, and calculate dot and cross products using an interactive
MATLAB code.
Objective:
1. To perform the following coordinate transformations –
Input Output1 Output2
Rectangular coordinate Cylindrical coordinate Spherical coordinate
Cylindrical coordinate Rectangular coordinate Spherical coordinate
Spherical coordinate Rectangular coordinate Cylindrical coordinate
2. To perform dot product of user defined vectors.
3. To perform cross product of user defined vectors.
Theory:
Page No
MATLAB Code:
% Purpose: perform coordinate transformation
% Script Filename: PE1Expt1.m
% Name-
% Registration Number-
%Date-
clc
clear all
close all
x= input('Enter X : ');
y= input('Enter Y : ');
z= input('Enter Z : ');
rho=sqrt(x^2+y^2);
fi=atand(y/x);
r=sqrt(x^2+y^2+z^2);
theta=atand(sqrt(x^2+y^2)/z);
disp('Cylindrical Coordinate ')
disp(rho)
disp(180+fi)
disp(z)
disp('Spherical Coordinate ')
disp(r)
disp(theta)
disp(180+fi)
% Cylindrical Coordinate to Cartesian and Spherical Coordinate
rho= input('Enter Rho : ');
fi= input('Enter Fi : ');
z= input('Enter Z : ');
r=sqrt(rho^2+z^2);
theta=atand(rho/z);
x=rho*cos(fi);
y=rho*sin(fi);
disp('Spherical Coordinate ')
disp(r)
disp(theta)
disp(180+fi)
disp('Cartesian Coordinate ')
disp(x)
disp(y)
disp(z)
Page No
% Spherical Coordinate to Cartesian and Cylindrical Coordinate
r= input('Enter R : ');
theta= input('Enter Theta : ');
fi= input('Enter Fi : ');
rho=r*sin(theta);
z=r*cos(theta);
Page No
x=r*sin(theta)*cos(fi);
y=r*sin(theta)*sin(fi);
disp('Cylindrical Coordinate ')
disp(rho)
disp(180+fi)
disp(z)
disp('Cartesian Coordinate ')
disp(x)
disp(y)
disp(z)
% DOT PRODUCT AND CROSS PRODUCT
function vector_operations()
disp('Enter the components of the first vector :');
A = input('Vector A = ');
disp('Enter the components of the second vector :');
B = input('Vector B = ');
if length(A) ~= 3 || length(B) ~= 3
error('Both vectors must be 3-dimensional.');
end
dot_product = calculate_dot_product(A, B);
fprintf('Dot Product of Vector A and Vector B: %.2f\n',dot_product);
cross_product = calculate_cross_product(A, B);
fprintf('Cross Product of Vector A and Vector B: [%s]\n',num2str(cross_product));
end
function dot_product = calculate_dot_product(A, B)
dot_product = A(1) * B(1) + A(2) * B(2) + A(3) * B(3);
end
function cross_product = calculate_cross_product(A, B)
cross_product(1) = A(2) * B(3) - A(3) * B(2);
cross_product(2) = A(3) * B(1) - A(1) * B(3);
cross_product(3) = A(1) * B(2) - A(2) * B(1);
end
vector_operations();
Test Results:
4
7
Enter Y : Enter Z :
6
Cylindrical Coordinate
8.0623
240.2551
Spherical Coordinate
10.0499
53.3431
240.2551
Page No
Enter Rho :
34
Enter Fi :
56
Enter Z :
9
Spherical Coordinate
35.1710
75.1735
236
Cartesian Coordinate
29.0095
-17.7327
Enter R :
12
Enter Theta :
45
Enter Fi :
46
Cylindrical Coordinate
10.2108
226
6.3039
Cartesian Coordinate
-4.4129
9.2080
6.3039
Enter the components of the first vector :
Vector A =
[1 1 1]
Enter the components of the second vector :
Vector B =
[2 4 6]
Dot Product of Vector A and Vector B: 12.00
Cross Product of Vector A and Vector B: [2 -4 2]
Page No
Conclusions:
Page No
Page No