lab exam
lab exam
Matlab
matlab
Copy code
% Input
factorial_result = 1;
for i = 1:n
factorial_result = factorial_result * i;
end
% Output
fprintf('The factorial of %d
4o mini
You said:
ChatGPT said:
ChatGPT
Here are the shortest possible versions of the MATLAB solutions for each task:
matlab
Copy code
disp(f);
matlab
Copy code
function p = isPrime(n)
p = all(mod(n, 2:n-1) > 0);
end
matlab
Copy code
A = [1 2 3; 4 5 6];
sum_val = sum(A(:));
disp(sum_val);
4. Fibonacci Series:
matlab
Copy code
n = input('Enter n: ');
disp(f);
matlab
Copy code
a = 0; b = 3; tol = 1e-6;
c = (a+b)/2;
end
disp(c);
6. Palindrome Check:
matlab
Copy code
7. Roots of a Polynomial:
matlab
Copy code
p = [1 -6 11 -6];
r = roots(p);
disp(r);
matlab
Copy code
f = @(x) x.^2;
a = 0; b = 2; n = 4; h = (b-a)/n;
x = a:h:b; y = f(x);
disp(I);
matlab
Copy code
A = [4 1; 2 3];
disp(eigVecs);
disp(diag(eigVals));
matlab
Copy code
a = 3; b = 9;
disp(c);
matlab
Copy code
disp(A*(B*C) == (A*B)*C);
12. Plot Sine and Cosine:
matlab
Copy code
x = 0:0.1:2*pi;
matlab
Copy code
fplot(f_prime, [0 2*pi]);
matlab
Copy code
z = x.^2 - y.^2;
surf(x, y, z);
matlab
Copy code
x = 0:0.1:2*pi;
y1 = 2*sin(x); y2 = cos(cos(x));
legend('2sin(x)', 'cos(cos(x))');
matlab
Copy code
scatter(x, y);
xlabel('X-axis'); ylabel('Y-axis');
1. Arithmetic Operations:
python
Copy code
a, b = 10, 5
2. Print Pattern:
python
Copy code
fahrenheit = (temp * 9 / 5) + 32
if X % 5 != 0: print(-1)
python
Copy code
python
Copy code
python
Copy code
a, b, c = 3, 5, 7
print(max(a, b, c))
python
Copy code
python
Copy code
a, b = 3, 6
fact = 1
python
Copy code
python
Copy code
python
Copy code
python
Copy code
python
Copy code
p, r, t = 1000, 5, 2
SI = (p * r * t) / 100
CI = p * ((1 + r / 100) ** t - 1)
python
Copy code
python
Copy code
even_sum, odd_sum = 0, 0
if i % 2 == 0: even_sum += i
else: odd_sum += i
These are the shortest versions of the programs for each task.