clc; y = input('Please Enter the size of the equation system n = '); C = input('Please Enter the elements of the Matrix C '); b = input('Please Enter the elements of the Matrix b '); dett = det(C); if dett == 0 disp('This system is unsolvable because det(C) = 0 ') else b = b'; a = [C b]; % Gauss elimination method [m, n] = size(a); for j = 1:m-1 for z = j+1:m if a(j,j) == 0 t = a(j,:); a(j,:) = a(z,:); a(z,:) = t; end end for i = j+1:m a(i,:) = a(i,:) - a(j,:) * (a(i,j) / a(j,j)); end end x = zeros(1, m); for s = m:-1:1 c = 0; for k = s+1:m c = c + a(s,k) * x(k); end x(s) = (a(s,n) - c) / a(s,s); end disp('Gauss elimination method:'); disp('Matrix A after elimination:'); disp(a(:,1:end-1)); disp('Solution vector:'); disp(x); end
Write, Run & Share Octave code online using OneCompiler’s Octave online compiler for free. It’s a simple and powerful platform to practice numerical computations and matrix operations using GNU Octave right from your browser.
GNU Octave is an open-source high-level programming language primarily intended for numerical computations. It is mostly compatible with MATLAB, and it's commonly used for linear algebra, numerical analysis, signal processing, and other scientific computing tasks.
The following is a simple Octave program that prints a greeting:
printf("Hello, OneCompiler!\n");
OneCompiler’s Octave editor supports stdin through the I/O tab. Here's an example of reading input from the user:
name = input("Enter your name: ", "s");
printf("Hello, %s!\n", name);
a = 10;
b = 3.14;
name = "Octave";
v = [1, 2, 3];
M = [1, 2; 3, 4];
Operation | Syntax |
---|---|
Add | + |
Subtract | - |
Multiply | * |
Divide | / |
Element-wise | .* , ./ |
x = 10;
if x > 5
disp("x is greater than 5");
else
disp("x is 5 or less");
end
for i = 1:5
disp(i);
end
i = 1;
while i <= 5
disp(i);
i = i + 1;
end
function y = square(x)
y = x ^ 2;
end
result = square(4);
printf("Square: %d\n", result);
This guide provides a quick reference to Octave programming syntax and features. Start writing Octave code using OneCompiler’s Octave online compiler today!