My First Derivative is not correctly calculated in matlab

2 次查看(过去 30 天)
syms yApprox(X1) a0 a1 a2 a3 a4 a5 a6
yApprox = a0 + a1.*X1 + a2.*(X1).^2 + a3.*(X1).^3+ a4.*(X1).^4 + a5.*(X1).^5 + a6.*(X1).^6;
BC1= subs(yApprox,X1,0)
BC2 =subs((diff(yApprox)),X1,0) %The answer is suppose to be a1 but instead of that i got 1

采纳的回答

Bruno Luong
Bruno Luong 2024-3-21
编辑:Bruno Luong 2024-3-21
syms yApprox(X1) a0 a1 a2 a3 a4 a5 a6
yApprox = a0 + a1.*X1 + a2.*(X1).^2 + a3.*(X1).^3+ a4.*(X1).^4 + a5.*(X1).^5 + a6.*(X1).^6;
BC1= subs(yApprox,X1,0)
BC1 = 
BC2 =subs((diff(yApprox,X1)),X1,0) % pay attention to diff(..)
BC2 = 

更多回答(1 个)

Manikanta Aditya
Manikanta Aditya 2024-3-21
Hey,
Looks like the issue you are encountering is due to the differentiation operation. When you differentiate 'yApprox' with respect to X1, the coefficient a1 is treated as a constant, and the derivative of X1 with respect to X1 is 1. That’s why you’re getting 1 instead of a1.
syms X1 a0 a1 a2 a3 a4 a5 a6
yApprox = a0 + a1.*X1 + a2.*(X1).^2 + a3.*(X1).^3+ a4.*(X1).^4 + a5.*(X1).^5 + a6.*(X1).^6;
BC1= subs(yApprox,X1,0);
diff_yApprox = diff(yApprox, X1);
BC2 = subs(diff_yApprox, X1, 0);
In this code, 'diff_yApprox' is the derivative of 'yApprox' with respect to X1. When X1=0 is substituted into 'diff_yApprox', the result should be a1 as expected.
Thanks!

类别

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

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by