SCRIBD

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

EXAMPLES OF SOME PROGRAMS IN MATLAB.

1. Program for computing k, given x & y values:


x=input('enter the value of x,x=')
y=input('enter the value of y,y=')
k=(sqrt((x^2*cosh (100*y^3)) + csc(sqrt(4*y))))/(sinh(x^2)-20*10^-8)

2. Program for computing k, given x & y values:


x=input('enter the value of x,x=')
y=input ('enter the value of y,y=')
k= cos (sin (5*x*sin(4*x^6))/(1-atanh((1-x)/y^2)))
plot(k,y,'*g')

3. Program to show the various format options:


a=input('enter the value of a,a=')
b=input('enter the value of b,b=')
c=input('enter the value of c,c=')
y=a^4+(b^9/4)-6*(c)^(1/3)
%disp will only show value of the variable without the variable as well.
format long e
disp(y)
format short g
disp (y)
format long g
disp(y)
plot(a,y,'+r')
4. Program to show the various format options:
a=input('enter the value of a,a=')
b=input('enter the value of b,b=')
c=input('enter the value of c,c=')
y=a^2+(b^5/4)-6*(c)^(1/3)
%disp will only show value of the variable without the variable as well.
format long e
disp(y)
format short g
disp (y)
format long g
disp(y)
plot(a,y,'+r')

5. % Multiple Curves example using option 1


s= -2:0.01:4; %ranges of s
y= s.^2 -2.*s+7;%y(s) funxns
T=s + 4; % T(s) function
figure (1)
plot(s,y,'k', s,T,':k') % first option
grid on
xlabel ('Time[s]')
ylabel ('speed[rad/s]')
legend ('Quadratic','Linear')

figure(2)
plot(s,y,'or', s,T,'*b') %second option
grid on
xlabel('Time[s]')
ylabel('speed[rad/s]')
legend('Quadratic', 'Linear')

6. % Plot of polynomial of the 5th order


x=(-2:.05:2);
write the program format for the equation below for the range of x given above.
p=a5*x.^5+a4*x.^4+a3*x.^3+a2*x.^2+a1.*x+a0
y=m.*x+c
plot(x,p,'-*r')
grid on
hold on
plot(x,y,':og')

You might also like