Need to host a subversion repository? Try our hosted development tools.

Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 553
Number of posts: 954

This Forum Only
Post New Thread

Report
Evaluate Function using vectors Posted by soulbeginner on 4 Nov 2009 at 6:25 PM
How would I evaluate this using a row vector? (pref no loops! (its horrible!)
function [y, err] = arctanseries(x,n) -> x is the row vector, n is just an integer.

Thank you in advance to all who try!

function [y, err] = arctanseries(x,n)

if(x>=(-1))&(x<=1)
    power = [];
    nom = [];
    denom = [];
    neg = [];
    answer = [];
    
    % Vector neg, alternating values, 1 -1 1 -1 for arctanseries
    neg = ones(1,n);
    neg(2:2:end) = -1;
    
    % Vector power, starts at 1, increases by 2 for n-1 times
    power = 1:2:((2*n)-1);
    
    % Vector denom, denominator of the arctanseries. stats at 1
    denom = 1:2:((2*n)-1);
    
    % Vector nom, nominator equals x
    nom = (ones(1,n))*x;
    
    % solve arctan series 
    answer = nom .^ power;
    answer = answer .* neg;
    answer = sum(answer ./ denom);
    
    % ***Output***
    y = answer;
else
    err = error('Input Error: x must be between -1 and 1 inclusive')
end





 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.