indexamc_merged
indexamc_merged
Submitted To:
Dr. Vivek kumar dwivedi
Submitted By:
Sarthak Lakhera
23119030
A18
INDEX
S.No Experiment Date Remarks
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Sarthak Lakhera 23119030 A18
Q1. A=[9,10,20,21,24] , B=[1,2,3,4,5] find minimum.maximum,mean , std. Variation and sum. Also
dot, cross product of A & B and inverse of (A/B).
Ans1.
A=[9,10,20,21,24];
B=[1,2,3,4,5];
a=mean(A);
b=max(A);
c=min(A);
d=sum(A);
e=median(A);
f=std(A);
g=dot(A,B);
i=inv(A./B);
j=rand(1,128);
Output-
a =16.8000
b =24
c =9
d =84
e =20
f =6.8337
g =293
i=0.1877
Q3. Find out roots of polynomial equation 5x^5 + 7x^4+2x^2-6x+10 using matlab .
Ans 3.
x=[5 7 0 2 -6 10];
y=roots([5 7 0 2 -6 10]);
Output-
y= -1.8652 + 0.0000i
-0.4641 + 1.0832i
-0.4641 - 1.0832i
0.6967 + 0.5355i
0.6967 - 0.5355i
Learning Outcome:
Perform basic mathematical operations (mean, std, dot/cross product) and matrix manipulations
in MATLAB.
Generate and analyze random data for simulations and signal processing.
EXPERIMENT 2
Objective:
To determine the least square fit and curve fit for given data points and plot them using suitable
mathematical models and functions like polyfit, polyval, and lsqcurvefit in MATLAB or similar
platforms.
Theory:
1. Introduction
Curve Fitting:
Curve fitting is the process of finding a curve (or mathematical function) that best fits a series of data
points. This is widely used in engineering, physics, and data analysis to predict trends and analyze
behaviors.
o The model is a straight line y=ax+by = ax + by=ax+b, where aaa (slope) and bbb
(intercept) are determined using the least squares method.
4.1. Polyfit
p = polyfit(x, y, n);
x, y: Data points.
4.2. Polyval
4.3. Lsqcurvefit
x, y: Data points.
You can define a custom model function for lsqcurvefit. For example:
Learning Outcome:
Understand least square fitting and curve fitting using mathematical models.
Apply functions like polyfit, polyval, and lsqcurvefit for data analysis in MATLAB.
Visualize and interpret fitted curves and their accuracy for given data points.
close all;
clear all;
Xaxis = [1,3,5,7,9,11,13,15];
Yaxis = [4,9,23,37,73,103,133,179];
coeff = polyfit(Xaxis,Yaxis,1);
plt = polyval(coeff,Xaxis);
subplot(3,3,1);
plot(Xaxis, Yaxis);
coeff1 = polyfit(Xaxis,Yaxis,2);
plt1 = polyval(coeff1,Xaxis);
subplot(3,3,2);
plot(Xaxis, Yaxis );
coeff2 = polyfit(Xaxis,Yaxis,3);
plt2 = polyval(coeff2,Xaxis);
subplot(3,3,3);
plot(Xaxis, Yaxis);
coeff3 = polyfit(Xaxis,Yaxis,4);
plt3 = polyval(coeff3,Xaxis);
subplot(3,3,4);
plot(Xaxis, Yaxis);
coeff4 = polyfit(Xaxis,Yaxis,5);
plt4 = polyval(coeff4,Xaxis);
subplot(3,3,5);
plot(Xaxis, Yaxis);
ques 2
Xdata = [0.9, 0.15, 13.8, 19.8, 24.1, 28.2, 35.2, 60.3, 74.6, 81.3];
Ydata = [455.2, 428.2, 124.1, 67.3, 43.2, 28.3, 13.1, -0.4, -1.3, -1.5];
figure;
plot(Xdata, Ydata, 'o');
hold on;
plot(Xdata, Yfit, '-');
grid on;
xlabel('Xdata');
ylabel('Ydata');
title('Curve Fitting using Exponential Model');
plot(m, g, 'o');
hold on;
plot(m_fit, g_fit, '-');
grid on;
xlabel('m');
ylabel('g');
title('Linear Fit for Given Data');
figure;
plot(t, p, 'o');
hold on;
plot(t, p_fit, '-');
grid on;
xlabel('t');
ylabel('p');
title('Least Squares Fit');
Experiment-3
Aim:
To understand and implement Interpolation & Data
analysis/statistics in matlab.
Software used:
MATLAB
In Lab Exercise:
Solution code:
clc
close all
clear all
x = linspace(0,10,11);
y = cos (x);
xnew = linspace(0,10,1000);
stem(x,y)
hold on
ynew1 = interp1(x,y,xnew,'nearest');
plot(xnew,ynew1)
ynew2 = interp1(x,y,xnew,'linear');
plot(xnew,ynew2)
ynew3 = interp1(x,y,xnew,'spline');
plot(xnew,ynew3)
hold off
title("Comparision between diffferent techniques of interpolation")
grid on
legend("original","nearest","linear","spline")
SARTHAK LAKHERA 23119030
SARTHAK LAKHERA 23119030
Solution code:
clc
close all
clear all
x = [0 0.785 1.570 2.536 3.141 3.927 4.712 5.497 6.283]
y = [0.00 0.707 1.00 0.707 0.00 -0.707 -1.00 -0.707 -0.00]
xnew = linspace(0,6.3,1000);
stem(x,y)
hold on
ynew1 = interp1(x,y,xnew,'nearest');
plot(xnew,ynew1)
ynew2 = interp1(x,y,xnew,'linear');
plot(xnew,ynew2)
ynew3 = interp1(x,y,xnew,'spline');
plot(xnew,ynew3)
hold off
title("Comparision between diffferent techniques of interpolation")
grid on
legend("original","nearest","linear","spline")
Learning Outcome:
● Learnt about interpolation techniques and implemented them.
● Learnt about the implementation of hold function and legend
function.