My First Derivative is not correctly calculated in matlab

2 vues (au cours des 30 derniers jours)
inzamam shoukat
inzamam shoukat le 21 Mar 2024
Commenté : inzamam shoukat le 21 Mar 2024
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

Réponse acceptée

Bruno Luong
Bruno Luong le 21 Mar 2024
Modifié(e) : Bruno Luong le 21 Mar 2024
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 = 

Plus de réponses (1)

Manikanta Aditya
Manikanta Aditya le 21 Mar 2024
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!

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by