calculate the function in vector.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JaeSung Choi
el 12 de Jun. de 2017
Comentada: JaeSung Choi
el 13 de Jun. de 2017
I want to calculate my 'poly' function for domain of linspace(0,1,100) so I tried ---------------------------------
%make poly function
function [output] = poly(input)
output= ([input^0 input^1 input^2 input^3 input^4 input^5]*transpose([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]) )
end
----------------------------------
x = linsapce(0,1,100)
poly(x)
----------------------------------
but it doesn't work. I found that for sin(x) it does. I want to know what's different between to func. and how to solve the problem.
1 comentario
KSSV
el 12 de Jun. de 2017
What is the input you used? You have to take care of element by element operations.
Respuesta aceptada
Andrei Bobrov
el 13 de Jun. de 2017
Editada: Andrei Bobrov
el 13 de Jun. de 2017
function [output] = AsPolyvalForJaeSung(input)
output = bsxfun(@power,input(:),0:5)*[1.0000;1.0001;0.4991;0.1703;0.0349;0.0139];
end
Más respuestas (2)
KSSV
el 12 de Jun. de 2017
For
input = linspace(0,1,100) ;
In the line
output= ([input.^0 input.^1 input.^2 input.^3 input.^4 input.^5]*transpose([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]) )
The size of term in square braces would be 1X600 where as the term transpose i.e second term got only 6X1 terms. How you expect them to multiply? You need to rethink on your code.
Torsten
el 12 de Jun. de 2017
output= ([(input.').^0 (input.').^1 (input.').^2 (input.').^3 (input.').^4 (input.').^5]*([1.0000 1.0001 0.4991 0.1703 0.0349 0.0139]).'
Best wishes
Torsten.
2 comentarios
Torsten
el 13 de Jun. de 2017
??
According to your question, I think this is exactly what you needed.
Best wishes
Torsten.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!