Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MATLAB Simulated Experiment-1a, Lab Reports of Mathematics

This is the simulated result of MATLAB experiment 1a

Typology: Lab Reports

2020/2021

Uploaded on 03/21/2022

scarletboo
scarletboo 🇮🇳

5 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EXPERIMENT 1-A
1. Using MATLAB find the tangent to the curves y=
x
at x=4 at show graphically.
Solution:
The tangent to the line of the curve y=f(x) at the point P (a, f(a)) is the line through P with the slope m=f’(a)=
lim
h→ 0
f
(
a+h
)
f(a)
h
The following code illustrate the plotting of the tangent to the curve y=
x
at the point x=4.
clear all
clc
syms x y
f = input (‘Enter the given function in variable x:’);
x0 = input (‘Enter the x-coordinate of the point:’);
y0 = subs (f, x, x0);
fx = diff (f, x);
m = subs (fx, x, x0);
tangent = y0+m*(x-x0);
t_line = y-tangent;
plotrange = [x0-3, x0+3];
ezplot (f, plotrange);
hold on;
ezplot (tangent, plotrange)
title (‘Tangent line plot’)
t = sprintf (‘The tangent to the curve y=%s at (%d, %d) is y=%s’, f, x0, y0, tangent’);
disp (t)
Input : Enter the given function in variable x: sqrt(x)
Enter the x-coordinate of the plot: 4
Output: The tangent to the curve y=x^ (1/2) at (4,2) is y=x/4 + 1
2. Using MATLAB find the tangent to the curves y=-sin(x/2) at the origin and show graphically.
Solution:
pf3
pf4
pf5

Partial preview of the text

Download MATLAB Simulated Experiment-1a and more Lab Reports Mathematics in PDF only on Docsity!

EXPERIMENT 1-A

1. Using MATLAB find the tangent to the curves y= √ x at x=4 at show graphically.

Solution:

The tangent to the line of the curve y=f(x) at the point P (a, f(a)) is the line through P with the slope m=f’(a)=

lim

h→ 0

f ( a + h ) − f ( a )

h

The following code illustrate the plotting of the tangent to the curve y= √ x at the point x=4.

clear all clc syms x y f = input (‘Enter the given function in variable x:’); x0 = input (‘Enter the x-coordinate of the point:’); y0 = subs (f, x, x0); fx = diff (f, x); m = subs (fx, x, x0); tangent = y0+m*(x-x0); t_line = y-tangent; plotrange = [x0-3, x0+3]; ezplot (f, plotrange); hold on; ezplot (tangent, plotrange) title (‘Tangent line plot’) t = sprintf (‘The tangent to the curve y=%s at (%d, %d) is y=%s’, f, x0, y0, tangent’); disp (t)

Input : Enter the given function in variable x: sqrt(x)

Enter the x-coordinate of the plot: 4

Output: The tangent to the curve y=x^ (1/2) at (4,2) is y=x/4 + 1

2. Using MATLAB find the tangent to the curves y=-sin(x/2) at the origin and show graphically.

Solution:

The tangent to the line of the curve y=f(x) at the point P (a, f(a)) is the line through P with the slope m=f’(a)=

lim h→ 0 f ( a + h ) − f ( a ) h

The following code illustrate the plotting of the tangent to the curve y=-sin(x/2)

clc syms x y f = input (‘Enter the given function in variable x:’); x0 = input (‘Enter the x-coordinate of the point:’); y0 = subs (f, x, x0); fx = diff (f, x); m = subs (fx, x, x0); tangent = y0+m*(x-x0); t_line = y-tangent; plotrange = [x0-3, x0+3]; ezplot (f, plotrange); hold on; ezplot (tangent, plotrange) title (‘Tangent line plot’) t = sprintf (‘The tangent to the curve y=%s at (%d, %d) is y=%s’, f, x0, y0, tangent’); disp (t)

Input : Enter the given function in variable x: -sin(x/2)

Enter the x-coordinate of the point : 0

Output : The tangent to the curve y= -sin(x/2) at (0,0) is y=-x/

3. Verify Rolle’s theorem for the function (^) ( x + 2 )^3 ( x − 3 )^4 in the interval [2,3]. Plot the curve along with the

secant joining the end points and the tangents at points which satisfy Rolle’s theorem.

Solution:

Rolle’s theorem: Suppose that the function y  f (x) is continuous at every point of the closed interval [a, b] and

differentiable at every point in (a, b) and if f (a)  f (b), then there is at least one number c in (a, b) at which f  (c) 

The below code illustrates the verification of Rolle’s theorem for the function f(x)= ( x + 2 )^3 ( x − 3 )^4 on the

interval [-2, 3].

4. Verify Lagrange’s mean value theorem for the function f(x)=x+e^3 x^ in the interval [0,1]. Plot the curve along with

the secant joining the end points and the tangents at points which satisfy Lagrange’s mean value theorem.

Solution:

Suppose that the function y  f (x) is continuous at every point of the closed interval [a, b] and differentiable at

every point in (a, b), then there is at least one number c in (a, b) so that

f’(c)= f ( b )− f ( a ) ba The below code illustrates the verification of Lagrange’s theorem for the function f(x)=x+e^3 x^ on the interval [0,1] clear all; clc; syms x c; f=input ('Enter the function: '); I=input ('Enter the interval [a, b]: '); a=I (1); b=I (2); fa=subs (f, x, a); fb=subs (f, x, b); df=diff (f, x); dfc=subs (df, x, c); LM=dfc-(fb-fa)/(b-a); c=solve (LM); count=0; for i=1: length(c) if c(i)>a && c(i) count=count+1; tx (count)=c(i); end end fprintf ('The values of c between %d and %d which satisfy LMVT are x=', a, b); disp(double(tx)) xval=linspace (a, b,100); yval=subs (f, x, xval); m=subs (df, tx); % Slopes of tangents at the points between a and b. ty=subs (f, x, tx); plot (xval, yval); hold on;

secant_slope=(fb-fa)/(b-a); secant_line=fa+secant_slope(x-a); sx_val=xval; sy_val=subs (secant_line, x, sx_val); plot (sx_val, sy_val); for i=1: length(tx) txval=linspace(tx(i)-1, tx(i)+1,20); t_line=ty(i)+m(i)(x-tx(i)); tyval=subs (t_line, x, txval); plot (txval, tyval,'k'); hold on plot(tx(i), ty(i),'ok'); end hold off; grid on legend ('Function', 'Secant', 'Tangents'); title ('Demonstration of LMVT');

Input : Enter the function: x+exp(3*x)

Enter the interval [a, b]: [0,1]

Output : The values of c between 0 and 1 which satisfy LMVT are x=0.