Matlab: Make A Program To Calculate The Value of Epsilon in Two Different Ways

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Matlab

Make a program to calculate the value of epsilon in two different ways


EBS=1;
for n=1:1000
EBS=EBS/2;
if (1+EBS)<= 1

EBS=EBS*2;
break

end
end

disp(EBS)

num=0; EBS=1;

while (EBS+1)>1
EBS=EBS/2;
num=num+1;
end

EBS=EBS*2;
disp(num);
disp(EBS);

A function to calculate the sum of four numbers:

A function to calculate the volume of cone


function [ Ahmed ] = avrg(r1,r2,r3,r4)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here

Ahmed=(r1+r2+r3+r4)/4;

end

function [volume2] = volumecone(r,h)


volume2=(1/3)*r*(h^3);

end

Ahmed Radwan Muhamed Ali


Matlab
A program to change temperatures from Celsius to Fahrenheit :
x_c=input('enter temp matrix 4 elements by four: ');
% input must be a matrix with four elements eg. [1 2 3 4]

for i=1:4
x_f=(5/9)*(x_c(i))+32;
disp('the temperature in fehrenhite is: ');
disp(x_f);
end

Student grades :
percent=input('the degree out of 100 is: ');

if percent > 100


grade = ('invalid input');
elseif percent >85
grade=('excellent');
elseif percent > 75
grade=('very good');
elseif percent > 65;
grade=('good');
elseif percent > 50;
grade=('passed');
else
grade=('A failure');
end

disp('the degree is ');


disp('grade');

for n =1:100
marks=input('the mark out of 100 equals = ');

while marks <100


if marks >=85;
grade='excellent';
elseif marks>=75;
grade='very good';
elseif marks >= 65;
grade='good';
elseif marks >=50

Ahmed Radwan Muhamed Ali


Matlab
grade='accepted';
else grade = 'failed yala ro7 lomk';
end;
display(marks);
display(grade)
break
end
while marks > 100
display('es7a yasta');
break
end

end

The money of an agent In a bank after number of years


increases due to profit, make a prog
money=input('enter your money amount: ');
years=input('number of years equals: ');
profit=input('enter the profit percent: ');

totalmoney= money + money*profit*years;


disp('the total money is ')
disp(totalmoney);

Function m file mid term 2008 group 1


function
[ s,area,innercirclearea,outercirclearea,alpha,be
ta,gamma,ha,hb,hc ] = trianglee(a,b,c)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
s=(a+b+c)/2
area=sqrt(s*(s-a)*(s-b)*(s-c))
innercirclearea = pi*((area/s)^2)
outercirclearea = ((a*b*c)/(4*area)^2)*(pi)
alpha=asin((2*area)/(a*b))
beta=asin((2*area)/(a*c))
gamma=asin((2*area)/(b*c))
ha = (2*area)/a
hb = (2*area)/b

Ahmed Radwan Muhamed Ali


Matlab
hc = (2*area)/c

end

:Make a program to calculate an array summation


n=input('enter matrix: ');
[r,x]=size(n);
sum=0;
for i=1:r
for z=1:x
sum=sum+n(i,z);
end
end
disp(sum)
n = input('enter the matrix ');
sum=0;
for i=1:numel(n)

sum=sum+n(i);
end
disp(sum)

Make a program to calculate the summation of numbers from


zero to that number and the summation of the squares of
numbers also
‫برنامج يحسب مربعات االعداد من صفر لرقم معين ومجمو ع هذه االعداد‬

x=input('enter the integer value: ');

sum=0;sum1=0;
for i=1:x
sum=sum+(i^2);
sum1=sum1+i;

end

disp('the summation of number is ')


disp(sum1)
disp('the square summation is ')

Ahmed Radwan Muhamed Ali


Matlab
disp(sum)

According to the relationship s=v.t-.5gt2, make a program to


calculate the distance as a variable of time and plot the
relationship (hint: time entered in minites and make the user
define the increment ,,, g = 9.81)
v=input('enter initial velocity: ');
tm=input('enter the time in minites: ');
n=input('enter time interval: ');

tmin=0:n:tm;
t=60*(0:n:tm);

g=9.81;
s=v*(t)-(.5)*(g)*(t.^2);

disp('the distance is ')


disp(s)
s1=s*(10^(-5));
plot(t,s1);xlabel('the
distance');ylabel('time');title('vertical motion
and gravity');

-: Make a function m-file to calculate the average of three numbers


function [ m ] = averagesectionfunc(x,y,z)

m=(x+y+z)/3;

end

:Make m-file to calculate the sum of two ages of two persons


age1=input('enter birth day: ');
age2=input('enter birth month ');
age3=input('enter birth year ');

age4=input('enter birh day of person 2: ');


age5=input('enter birth month of person 2: ');
age6=input('enter birth year of person 2: ');

Ahmed Radwan Muhamed Ali


Matlab
totaldays = age1 + age4;

totalmonths = age2 + age5;

totalyears = age3 + age6;

if totaldays > 30
totaldays = totaldays - 30;
totalmonths = totalmonths + 1;

end
if totalmonths > 12;
totalmonths = totalmonths - 12;
totalyears = totalyears + 1;
end

disp(totaldays);
disp(totalmonths);
disp(totalyears);

Make m-file to get valence of number


pos=input('enter val: ');
if pos<0
result=-pos;
else
result = pos;
end
disp(result)

A sock ( ‫ )حصالة‬contains a number of n1 of half-dollars, n2 of quarter-


dollars, n3 of 10 cents, n4 of 5 cents, and n5 of cents. How many dollars
in the sock? (One dollar is equivalent to 100 cents).

n1=input('half dollars number equals = ');


n2=input('quarter dollars number equals = ');
n3=input('10 cents coins number equals = ');
n4=input('number of 5 cents coins equals = ');
n5=input('number of cents is ');
dollars = (.5)*(n1) + (.25)*(n2)+ (.1)*(n3)+
(.05)*(n4) + .01*n5;
disp('the number of dollars is ');

Ahmed Radwan Muhamed Ali


Matlab
disp(dollars);
Make m-file to calculate the factorial of a number :
n=input('enter the number: ');

a=1;
for i=n:-1:1
a=a*i;
end
disp('the result is: ')
disp(a)

Make a script m-file to calc the summation of sequence :


for i=1:8
a=input('enter first value: ');
d=input('enter difference: ');
n=input('enter the number of elements: ');

sum=0;
for z = 1:n
sum=sum + a + z*d-d ;
end
disp('the sum is: ')
disp(sum)

end

Ahmed Radwan Muhamed Ali

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy