Trying to find the Lagrange's mean value theorom constant

5 Ansichten (letzte 30 Tage)
Soham Patil
Soham Patil am 12 Okt. 2021
Beantwortet: Nipun am 16 Apr. 2024
The script i wrote is
But i get these error
R =
root(z^4 + 2*z^2 - 5*z + 1, z, 1)
root(z^4 + 2*z^2 - 5*z + 1, z, 2)
root(z^4 + 2*z^2 - 5*z + 1, z, 3)
root(z^4 + 2*z^2 - 5*z + 1, z, 4)
Error using symengine
Unable to prove 'imag(root(z^4 + 2*z^2 - 5*z + 1, z, 1)) == 0 & 0 < real(root(z^4 + 2*z^2 - 5*z + 1, z, 1)) & real(root(z^4 + 2*z^2
- 5*z + 1, z, 1)) < 2' literally. Use 'isAlways' to test the statement mathematically.
Error in sym/subsindex (line 949)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym/subsref (line 997)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in exp_lmvt (line 14)
S=R(imag(R)==0&real(R)>a&real(R)<b)
clear
clf
clc
syms x
f(x)=input('Enter the function')
a=input('Enter the left endpoint')
b=input('Enter the right endpoint')
f_1(x)=diff(f,x)
fa=f(a)
fb=f(b)
m=(fb-fa)/(b-a)
C=m*(x-a)+fa
R=solve(f_1(x)==m,x)
S=R(imag(R)==0&real(R)>a&real(R)<b)
T=m*(x-S)+f(S)
fplot(f)
hold on
disp(char(S))
plot(a,f(a),'.','MarkerSize',25)
plot(b,f(b),'.','MarkerSize',25)
plot(S,f(S),'.','MarkerSize',25)
fplot(C)
fplot(T)
hold off

Antworten (1)

Nipun
Nipun am 16 Apr. 2024
Hi Soham,
I understand that you intend to find the constant "c" in Lagrange's mean value theorem given an equation using MATLAB.
Based on the given code, your input function should only be dependent on "x" and not any other variable, since only "x" is defined as a symbolic variable.
On running the code, with "x^2" as the function and "2", "5" as the left and right endpoints respectively, I get the follwing output as expected:
f(x) =
a = 2
b = 5
f_1(x) =
fa =
4
fb =
25
m =
7
C =
R =
S =
T =
7/2
Let me know if you face any trouble with any equation in "x" variable.
Hope this helps.
Regards,
Nipun

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by