My First Derivative is not correctly calculated in matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
inzamam shoukat
el 21 de Mzo. de 2024
Comentada: inzamam shoukat
el 21 de Mzo. de 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
0 comentarios
Respuesta aceptada
Bruno Luong
el 21 de Mzo. de 2024
Editada: Bruno Luong
el 21 de Mzo. de 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)),X1,0) % pay attention to diff(..)
Más respuestas (1)
Manikanta Aditya
el 21 de Mzo. de 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!
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!