# Mean_Value_Theorem.pdf - Name Aaditya Bhetuwal Regd No...

• 19
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 5 out of 19 pages.

Name: Aaditya Bhetuwal Regd. No.: 20BDS0406 Lab Slot : L59 + L60 – MATLAB – CFE Ex ercise Number: 1_A Date of Experiment: 29 th Jan, 2021 Title: Mean Value Theorem, Rolle’s Theorem and Plotting Tangents Aim: To verify Lagrange’s Mean Value Theorem, Rolle’ s Theorem, plotting tangents and doing some exercises. Program 1: The code given below illustrates the verification of Lagrange’s Mean Value Theorem over the given interval [-4,4]. MATLAB Code: clear all; clc; close all; syms x ; f(x) = x^3 - 12 * x - 5; interval = [-4,4] fx = diff(f(x),x) b = interval(2); a = interval(1); fc = (f(b) - f(a))/(b-a) crit = solve(fx == fc, x); crit = crit(crit>a & crit<b); disp("Critical points are :") disp(double(crit)) %tangent and secant
tan = f(crit) + fc * (x - crit); disp("The tangent lines are :") disp(vpa(tan,4)) figure(2) fplot(f(x), interval,"linewidth", 2, "DisplayName",'line1') hold on; fplot(tan, interval, "r","linewidth", 2,"DisplayName", 'line2') plot(interval, f(interval), "--m","linewidth", 2, "DisplayName", 'line3') plot(crit, f(crit),"sk", "DisplayName", 'line4' ) xlabel("X") ylabel("f(x) = x^3 - 12 * x - 5") title("Graph of f(x) and it's tangent") legend({'f(x)','tangent of f(x)',"secant of f(x)", "point of contact of tangent"}, "Location", "NorthWest") grid on; hold off;
Output:
Program 2: Using MATLAB find the tangent to the curve y = √x at x = 4 and show graphically . MATLAB Code: clear all; clc; close all; syms x; f(x) = sqrt(x); interval = [-10,10]; %x will be positive x_int = input("Enter x value :") fx = diff(f(x),x) b = interval(2); a = interval(1); m = subs(fx, x_int) %tangent and secant tan = f(x_int) + m * (x - x_int); disp("The tangent lines are :") disp(vpa(tan,4)) figure(2) fplot(f(x), interval,"linewidth", 2, "DisplayName",'line1') hold on; fplot(tan, interval, "r","linewidth", 2,"DisplayName", 'line2')