MATLAB Project
MATLAB Project
---
% Matrix multiplication
>> A = [1, 2; 3, 4];
>> B = [5; 6];
>> A * B
ans =
17
39
```
**Variables:**
```matlab
>> x = 7; % Scalar
>> y = [1, 2, 3]; % Row vector
>> z = y'; % Transpose (column vector)
```
---
**Indexing:**
```matlab
>> A = [10, 20, 30; 40, 50, 60];
>> A(2,3) % Row 2, Column 3 → 60
>> A(:,1) % All rows, Column 1 → [10; 40]
```
---
### 4. Plotting
**Simple 2D Plot:**
```matlab
>> x = 0:0.1:2*pi;
>> y = sin(x);
>> plot(x, y, 'r-', 'LineWidth', 2);
>> title('Sine Wave');
>> xlabel('x');
>> ylabel('sin(x)');
>> grid on;
```
*Output:* Smooth red sine wave graph.
**3D Surface:**
```matlab
>> [X,Y] = meshgrid(-2:0.1:2);
>> Z = X .* exp(-X.^2 - Y.^2);
>> surf(X, Y, Z);
>> colormap('jet');
```
*Output:* 3D surface plot of a Gaussian function.
---
**`for` Loop:**
```matlab
% Sum first 10 natural numbers
sum = 0;
for k = 1:10
sum = sum + k;
end
disp(['Sum = ', num2str(sum)]); % Output: Sum = 55
```
---
### 6. Functions
**User-Defined Function (`quadroots.m`):**
```matlab
function [x1, x2] = quadroots(a, b, c)
% Solves quadratic equation ax^2 + bx + c = 0
d = sqrt(b^2 - 4*a*c);
x1 = (-b + d) / (2*a);
x2 = (-b - d) / (2*a);
end
```
**Usage:**
```matlab
>> [r1, r2] = quadroots(1, -3, 2);
>> disp(['Roots: ', num2str(r1), ', ', num2str(r2)]);
% Output: Roots: 2, 1
```
---
% Plot results
plot(t, clean, 'b', t, noisy, 'g', t, smoothed, 'r', 'LineWidth', 1.5);
legend('Clean', 'Noisy', 'Filtered');
```
*Output:* Plot comparing clean, noisy, and filtered signals.
---
### 8. Conclusion
MATLAB simplifies complex mathematical tasks. Key strengths:
- Intuitive matrix operations
- Powerful visualization tools
- Extensive built-in libraries
- Rapid prototyping capabilities
**Challenges:**
- Licensing cost
- Slower than compiled languages (e.g., C++)
---
*End of Project*
*(Handwritten figures and graphs would be included in the original submission)*