Trying to find the Lagrange's mean value theorom constant

22 次查看(过去 30 天)
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

回答(1 个)

Nipun
Nipun 2024-4-16
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

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by