Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sistem();
- function [solution]=sistem()
- N=input("Unesite broj jednacina sistema: ");
- A=zeros(N);
- fprintf("Unesite matricu sistema:\n");
- for i=1:N
- for j=1:N
- fprintf("Unesite koeficijente na mjestu (%d,%d): ",i,j);
- A(i,j)=input("");
- end
- end
- fprintf("Unesite matricu jednakosti:\n");
- B=zeros(N,1);
- for i=1:N
- fprintf("Unesite element na mjestu (%d,%d): ",i,1);
- B(i,1)=input("");
- end
- solution=A\B;
- if(N==2)
- x=solution(1)-5:0.01:solution(1)+5;
- y1=(B(1,1)-A(1,1)*x)/A(1,2);
- y2=(B(2,1)-A(2,1)*x)/A(2,2);
- plot(x,y1,'r');
- hold on;
- grid on;
- plot(x,y2,'b');
- plot(solution(1),solution(2),'o');
- elseif(N==3)
- X=solution(1)-5:0.01:solution(1)+5;
- Y=solution(2)-5:0.01:solution(2)+5;
- [x,y]=meshgrid(X,Y);
- z1=(B(1,1)-A(1,1)*x-A(1,2)*y)/A(1,3);
- z2=(B(2,1)-A(2,1)*x-A(2,2)*y)/A(2,3);
- z3=(B(3,1)-A(3,1)*x-A(3,2)*y)/A(3,3);
- mesh(x,y,z1);
- hold on;
- mesh(x,y,z2);
- mesh(x,y,z3);
- plot3(solution(1),solution(2),solution(3),'o');
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement