Hello!
I try to plot userdefined function, but on screen only horizontal line at 50. What is wrong with my function? %========================================== function ua = fnUA(x) if x > 0.03 ua = 50*sin( 2*3.1415*50*x ); else ua = 50; end; endfunction x=[0:0.0001:0.09]; plot(x, fnUA(x)); %========================================= Thanks. -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
On Mon, Nov 20, 2017 at 6:44 AM, Andrey <[hidden email]> wrote: Hello! %============== function ua = fnUA(x) ua = zeros(size(x)); index = (x>0.3); % vector of 0's and 1's ua(index) = 50*sin( 2*3.1415*50*x(index) ); % evaluates your function only where there is a 1 in the index vectorua(~index) = 50; % puts 50 everywhere else endfunction %============== Or use arrayfun to call your original function on each element of x: x=[0:0.0001:0.09]; y = arrayfun(@fnUA, x);
plot(x, y); Hope this helps, James Sherman Jr. _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Thank you, James. Your advise helped me. 20.11.2017, 18:57, "James Sherman Jr." <[hidden email]>:
_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Free forum by Nabble | Edit this page |