Exercise 4 Program To Find The Solution For System of Equations

You might also like

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

Exercise 4

Program to find the solution for system of equations


clc;
a=zeros(3);
b=zeros(3,1);
for i=1:3
for j=1:3
a(i,j)=input("Enter the coefficient");

end

end
for i=1:3
b(i,1)=input("Enter the constants");
end
ainv=inv(a);
x=ainv*b;
disp("The solution:")
disp(x);

OUTPUT:

Enter the coefficient


9
Enter the coefficient
8
Enter the coefficient
-2
Enter the coefficient
2
Enter the coefficient
-3
Enter the coefficient
-1
Enter the coefficient
-3
Enter the coefficient
3
Enter the coefficient
-5
Enter the constants
14
Enter the constants
5
Enter the constants
8
The solution:
1.1397
-0.1213
-2.3566

Exercise 5

1.

x=[0:0.01:20];
y=sin(x);
plot(x,y)

2.

x=[0:pi/10:pi];
yl=cos(x);
y2=sin(x);
plot(x,y1,x,y2)

3.
x=[1 5 2.7 3 7 4.8];
explode=[0 1 0 0 1 0];
pie(x,explode)
colormap hsv

4.

x=[-2*pi:pi/6:2*pi];
y=tan(x);
plot(x,y,'-.bd')

5.
x=0:0.1:pi;
y1=sin(x);
subplot(2,2,1);
plot(x,y1);
subplot(2,2,2);
y2=cos(x);
plot(x,y2);
y3=x.^3;
subplot(2,2,3);
plot(x,y3);
subplot(2,2,4);
y4=exp(-x);
plot(x,y4);

You might also like