Showing posts with label Language. Show all posts
Showing posts with label Language. Show all posts

Sunday, August 06, 2006

Polyfitting in MATLAB

clc,clear
disp('Your Name')
t=[1,2,3,4,5,6];
y=[42,83,102,124,129,120];
coef=polyfit(t,y,2);
a1=coef(1);
a2=coef(2);
a3=coef(3);
disp('The values of g and vo are...')
g=-2*a1
vo=a2
yf=polyval(coef,t);
disp(' time y fitting y')
disp(' ')
disp([t',y',yf'])
plot(t,y,'o',t,yf)

Saturday, August 05, 2006

Rocket Trajectory for MATLAB 5.3

%Problem #2 Chapter #3 page 121 rocket trajectory

clc,clear

disp('Your Name')
disp('-')
disp('-')

t = 0:2:100;

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) >= 0 | h(n) <=0 [d, dtime] = max(h); [i, impact] = min(h); end
end
end
disp('This is the time in seconds after which the rocket starts to fall.')
t(dtime)
t(impact);
n = 1:51;
time = t(n);
[h(n)',time'];

for n = 1:51;
time = t(n);

h(n) = 60 + (2.13 * (time^2)) - (.0013 * (time^4)) + (.000034 * (time^4.751));
if h(n) <=0 disp('This is the time in seconds when the rocket has hit the ground.')
time
break
end
end

Saturday, July 22, 2006

More Practice

%Analytical theory
R1=1;
R2=2;
V1=12
Rth=R1+R2;
Ith=V1./Rth;
Vn1=Ith.*R1;
Vn2=Ith.*R2
V1=0:0.5:10
Ith=V1./Rth;
Vn1=Ith.*R1;
Vn2=Ith.*R2;
disp('Source volt Node Volt.')
Theory=[V1', Vn2']


subplot(2,2,1),plot(dcsweewb,Theory,'*'),title('Source vs. Node')
xlabel('Node voltage'),ylabel('Source voltage')
subplot(2,2,2),plot(pasweewb,'*'),title('Parameter Sweep')
xlabel('Resistance in ohms'),ylabel('Current in amps')
subplot(2,2,3),plot(transweb),title('Transient')
xlabel('Time in seconds'),ylabel('Node voltage')
subplot(2,2,4),plot(project1),title('Labview')
xlabel(''),ylabel('')

»
V1 =

12


Vn2 =

8


V1 =

Columns 1 through 7

0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

Columns 8 through 14

3.5000 4.0000 4.5000 5.0000 5.5000 6.0000 6.5000

Columns 15 through 21

7.0000 7.5000 8.0000 8.5000 9.0000 9.5000 10.0000

Tuesday, July 11, 2006

MATLAB 5.3: Two Age Programs

clc %For a SIMPLE solution
clear
age=input('Enter your age :')
if age > 65
disp('senior')
elseif age > 20
disp('adult')
elseif age > 13
disp('teen')
elseif age > 0
disp('child')
elseif age < style="color: rgb(204, 0, 0);">'unborn')
end



clc %For a RANGE solution
clear
age=input('Enter your age :')
if age < style="color: rgb(204, 0, 0);">'unborn')
elseif 0<=age & age <=12 disp('child')
elseif 13<=age & age <=19 disp('teen')
elseif 20<=age & age <=65 disp('adult')
else
disp('senior')
end

The homework solution was the second one but I came up with the first and it was accepted as the right answer.

Thursday, July 06, 2006

MATLAB 5.3: Data Files

This homework will ask a user to enter 10 lottery numbers in two panels and then display those numbers in a table also a MS-WORD file will be brought in and display along with all variables used. The first will be saved as an ASCII/.dat file.


%saving and loading files by Your Name Here


clc
lotto1=input('Enter 5 numbers for the first lottery ticket panel');
lotto2=input('Enter 5 different numbers for the second lottery ticket panel');
disp('pick 1 pick 2')
table=[lotto1',lotto2'];
disp(table)
save yournamehere51.dat table /ascii
load YNHword.txt
disp('This is a MS Word file created earlier.')
disp(YNHword)
who
clear

Enter 5 numbers for the first lottery ticket panel[1,2,3,4,5]
Enter 5 different numbers for the second lottery ticket panel[6,7,8,9,99]
pick 1 pick 2
1 6
2 7
3 8
4 9
5 99

This is a MS Word file created earlier.
4 6 7
12 23 76


Your variables are:

YNHword lotto1 lotto2 table

Monday, July 03, 2006

MATLAB 5.3: Plotting

We were given three variables x, y1 and y2 and are asked to make two graphs and show procedures and results.

%two graphs are to be plotted along with rows and columns
clc
disp('Your name here')
x=0:10;
y1=0:10:100;
y2=[0,1,4,9,16,25,36,49,64,81,100];
disp(y1);
disp([y1]');
firstcomp=y2(6);
disp(firstcomp)
subplot(2,1,1),plot(x,y1);
title('Homework #? Graph');
xlabel('X Values''Y1 Values');
subplot(2,1,2),plot(x,y1,x,y2,'o');
title('Homework #? Graph');
xlabel('X Values'),ylabel('Y2 Values')
Your name here
0 10 20 30 40 50 60 70 80 90 100

0
10
20
30
40
50
60
70
80
90
100

25