0% found this document useful (0 votes)
2 views

E2 CH 2_Script & Function

The document contains various MATLAB code snippets for calculating physical quantities such as distance, velocity, and volume of a sphere. It includes functions for converting degrees to radians, calculating polar coordinates, and averaging test scores. The code demonstrates the use of input prompts and formatted output for user interaction.

Uploaded by

8hvzctkjrz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

E2 CH 2_Script & Function

The document contains various MATLAB code snippets for calculating physical quantities such as distance, velocity, and volume of a sphere. It includes functions for converting degrees to radians, calculating polar coordinates, and averaging test scores. The code demonstrates the use of input prompts and formatted output for user interaction.

Uploaded by

8hvzctkjrz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

% Chapter 2 Spring 2025

clc
clear
format bank
g=9.8;
t=1:3:20;
y=.5*g*t.^2;
v=g.*t;
disp(' Time Distance Velocity')
Table=[t',y',v']

rad=0:pi/5:2*pi;
y=sin(rad)+cos(rad);
table=[rad',y']
[min,element]=min(y)
rad(element)

clc
clear
d=input('Enter Degree ');
r=pi/180*d;
fprintf('%f degree is equal to%f radian\n',d,r)

function [y1]=f(x1)
y1=5*x1^3+6*x1+5;
end

function [y1,y2]=f(x1,x2)
y1=5*x1^3+6*x1+5;
y2=6*x2;
end

function [y,v]=dist(t)
g=9.8;
y=.5*g*t.^2;
v=g*t;
end
>>[y,v]=dist(5)
Or
>>[y,v]=dist(1:8)

r=input('Enter the radius of the sphere:');


volume = (4.0/3.0)*pi*r.^3;
fprintf('The volume of a sphere with radius %5.3f is %5.3f \n', r, volume);
clc
clear
t=input('Enter the time ?');
g=9.8;
y=.5*g*t.^2;
v=g*t;
% Calculate distance
fprintf('the distance is = %5.2f\n',y);
% Calculate Velocity
fprintf('the velocity is = %5.2f\n',v);

%
x=input('enter value of x ?')
y=input('enter value of y ?')
r=sqrt(x.^2+y.^2);
alphar=atan2(x,y);
alphad=alphar*180/pi;
fprintf('r=%5.2f/n alpha=%5.2f',r,alphad)

%
r=input('ente value of r ? ')
alpha=input('enter value of alpha ? ')
x=r.*cosd(alpha);
y=r.*sind(alpha);
fprintf('x=%5.2f /n y=%5.2f',x,y)

function [r,alphad]=ptor(x,y)
r=sqrt(x.^2+y.^2);
alphar=atan2(x,y);
alphad=alphar*180/pi;
end

function [x,y]=pftorf(r,alpha)
x=r.*cosd(alpha);
y=r.*sind(alpha);
end

% Average Three Test


t1=input('test 1 ? ');
t2=input('Test 2 ? ');
t3=input('Test 3 ? ');
sum=t1+t2+t3;
avg=sum/3;
fprintf(' Test= %5.2f Test2=%5.2f Test3=%5.f2 Avg=%5.2f\n\n', t1,t2,t3,avg);

You might also like