Alternative to coeffs, giving incorrect answers, symbolic function coeffs
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Julio Beatriz
el 8 de Sept. de 2019
Comentada: Julio Beatriz
el 9 de Sept. de 2019
Hello, I have an expression in symbolic that looks like the following, as well as the following commands:
expr =
delta*lambda*g(2) + (delta*k*exp(-Ti*sigma*2i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (delta*k*exp(Ti*sigma*2i)*exp((To*wbar*1i)/2)*g(2))/2 + (delta*lambda*exp(-Ti*sigma*4i)*exp(-To*wbar*1i)*g(2))/2 + (delta*lambda*exp(Ti*sigma*4i)*exp(To*wbar*1i)*g(2))/2 + (A*delta*exp(-Ti*sigma*2i)*exp(To*wbar*1i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (A*delta*exp(Ti*sigma*2i)*exp(To*wbar*1i)*exp((To*wbar*1i)/2)*g(2))/2 + (Abar*delta*exp(-Ti*sigma*2i)*exp(-To*wbar*1i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (Abar*delta*exp(Ti*sigma*2i)*exp(-To*wbar*1i)*exp((To*wbar*1i)/2)*g(2))/2
[a,b]=coeffs( expr ,exp(i*wbar*To) );
number=find(b==exp(i*wbar*To));
Terms=a(number)
Problem is Terms is giving me the following result:
(delta*lambda*exp(Ti*sigma*4i)*g(2))/2 + (A*delta*exp(-Ti*sigma*2i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (A*delta*exp(Ti*sigma*2i)*exp((To*wbar*1i)/2)*g(2))/2
Which is wrong, as I dont want the bolded terms, as they are not exactly what I specified in the coeffs, I only want the underlined, italic, bolded part.
Is there anyway to fix this so it gives me the values with exactly exp(i*wbar*To) , or alternative methods that might work better ?
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Sept. de 2019
delta*lambda*g(2) + (delta*k*exp(-Ti*sigma*2i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (delta*k*exp(Ti*sigma*2i)*exp((To*wbar*1i)/2)*g(2))/2 + (delta*lambda*exp(-Ti*sigma*4i)*exp(-To*wbar*1i)*g(2))/2 + (delta*lambda*exp(Ti*sigma*4i)*exp(To*wbar*1i)*g(2))/2 + (A*delta*exp(-Ti*sigma*2i)*exp(To*wbar*1i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (A*delta*exp(Ti*sigma*2i)*exp(To*wbar*1i)*exp((To*wbar*1i)/2)*g(2))/2 + (Abar*delta*exp(-Ti*sigma*2i)*exp(-To*wbar*1i)*exp(-(To*wbar*1i)/2)*g(2))/2 + (Abar*delta*exp(Ti*sigma*2i)*exp(-To*wbar*1i)*exp((To*wbar*1i)/2)*g(2))/2
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
Three exact copies of the same subexpression exp(To*wbar*1i) . No matter whether you say that that is the same as exp(i*wbar*To) (different order of multiplication which does not matter because communtivity), you have to agree that all three need to be treated the same way. If you match even one of them then you have to match all three. You therefore should not expect that only one term should come out of coeffs.
3 comentarios
Walter Roberson
el 9 de Sept. de 2019
expand() the expression. Or simplify(). Or rewrite() 'sincos' and then simplify() and possibly rewrite back to 'exp' and possibly simplify() again.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!