Element multiplication and subtraction
Mostrar comentarios más antiguos
I'd like to run the following though I keep getting element multiplication/division errors:
Ron = 0.012;
RL = 0.003;
R = 6.667;
D = 0:0.001:.999;
M = (D/(1-D))*(1/( (2*Ron*D/(R*((1-D)^2)))+1+(RL/R)*(1/((1-D)^2)) ))
plot (D,M);
I've several permutations of placing dots in front of multiplication, division and raise to the power signs though I just cannot seem to get this to work.
How should "M" be written so that Matlab will accept it?
Thank you
Respuesta aceptada
Más respuestas (2)
James Tursa
el 26 de Mzo. de 2019
Editada: James Tursa
el 26 de Mzo. de 2019
If you are unsure, then just put dots next to every * and / and ^ operation. If a scalar happens to be involved it will still work as expected. E.g.,
M = (D./(1-D)).*(1./( (2.*Ron.*D./(R.*((1-D).^2)))+1+(RL./R).*(1./((1-D).^2)) ))
3 comentarios
Adam Danz
el 26 de Mzo. de 2019
The approach of putting dots in every multiplication, division, and exponent just to eliminate the error is a bad approach. Our two solutions are a great example why it's a bad approach. Your solution
M2 = (D./(1-D)).*(1./( (2.*Ron.*D./(R.*((1-D).^2)))+1+(RL./R).*(1./((1-D).^2)) ))
and my solution
M = (D/(1-D))*(1./( (2*Ron*D/(R*((1-D).^2)))+1+(RL/R)*(1./((1-D).^2)) ))
both produce a vector of the same size and shape but the values aren't equal. Both of our solutions "work" in that they avoid error but at least one of them must be incorrect and there's a good chance both are incorrect.
James Tursa
el 26 de Mzo. de 2019
Editada: James Tursa
el 26 de Mzo. de 2019
"... is a bad approach ..."
I will respectfully disagree on this one. Just looking at the variables there was obviously only one vector, namely D. So IMO it was quite likely he was just looking for element-wise operations in calculating M ... he was just unsure where to put the dots. Again, I am talking about this particular post only!
Adam Danz
el 26 de Mzo. de 2019
You took the time to realize that and it was a good call. My caution is against the preface "If you are unsure...". I don't think it is a good idea to throw a dot in, test it, and if there's no error, accept it without being certain that it's the correct correction. My answer is a good example of that.
Categorías
Más información sobre Get Started with Phased Array System Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!