
Math Software Math Software  Mathematica, Matlab, Calculators, Graphing Software 
 LinkBack  Thread Tools  Display Modes 
February 10th, 2016, 10:24 AM  #1 
Newbie Joined: Feb 2016 From: Pretoria Posts: 3 Thanks: 0  Octave crisis
Hi, I am using a software called octave to do calculations. Using the software, I am supposed to calculate the sum of the series: 1^2 +2^2 +3^2 +4^2...100^2. Please help!

February 10th, 2016, 10:37 AM  #2 
Math Team Joined: Jan 2015 From: Alabama Posts: 2,822 Thanks: 750 
What help do you want? Someone to tell you how to use the software? Do you have a manual for it?

February 10th, 2016, 12:10 PM  #3 
Newbie Joined: Feb 2016 From: Pretoria Posts: 3 Thanks: 0 
I do have a manual for it, but it is no good. I wish I knew where to study.

February 10th, 2016, 12:44 PM  #4 
Global Moderator Joined: Dec 2006 Posts: 18,154 Thanks: 1418 
You could do this for any function of the integers. If you define a function g, then sum(g([1:100])) gives the sum of its first 100 values. 
February 11th, 2016, 06:07 AM  #5 
Newbie Joined: Feb 2016 From: Pretoria Posts: 3 Thanks: 0 
Thank you skipjack. I truly appreciate your ingenuity.

February 29th, 2016, 06:21 AM  #6 
Math Team Joined: Nov 2010 From: Greece, Thessaloniki Posts: 1,989 Thanks: 133 Math Focus: pre pre pre pre pre pre pre pre pre pre pre pre calculus  simple for loop
Skipjack's way of computing is much faster. Here is a lightly heavier way (takes slightly much more time for the program to search in the libraries for  loop). Open with a notepad an empty file, name the file sqr_sum.m and then paste inside the following: % fprintf('This simple forloop calculates the sum : 1 + 2^2 + ... + n^2\n'); n = input('Enter the natural number n: '); if n<=0 fprintf('This is an invalid input! Sum will be computed for n = 1.\n') n = 1; end sum = 0; fprintf('Calculating ...'); for ii = 1 : n sum = sum + ii^2; end fprintf('The sum is: %i \n',sum); % Navigate octave to the folder that you saved your file and type: >sqr_sum Last edited by ZardoZ; February 29th, 2016 at 06:29 AM. 
February 29th, 2016, 07:28 AM  #7 
Senior Member Joined: Apr 2014 From: Glasgow Posts: 2,074 Thanks: 695 Math Focus: Physics, mathematical modelling, numerical and computational solutions 
The current answers are great. However, if it's the software writing part you find difficult (rather than the maths bit), consider a technique called 'writing pseudocode'. Pseudocode is a nice technique to help figure out what a program should look like... you just write out a set of instructions, stepbystep, about what sort of things you want the program to do. Start with a simple recipelike set of instructions and then go into more and more detail bit by bit. So, to begin with you'll probably have some really basic steps, like this 1. Input some numbers in 2. Calculate the series 3. Print the answers Okay... let's go into more detail... firstly, we don't have any numbers to input, so we can get rid of step 1. Secondly, a series has lots of terms in it, so we want to add up all those terms together to make a sum. So instead we might instead have something like this: 1. set the current sum to be 0 2. work out what the next term is 3. add this term to the current sum 4. repeat steps 34 until you've gone over all the terms 5. Print current sum to the screen Okay... let's try going into even more detail. Each term is calculated by squaring a number. The number to square goes up by 1 each time too: 1. set current sum = 0 2. set current number = 1 3. new term = current number squared 4. current sum = current sum + new term 5. current number = current number +1 6. repeat steps 35 until current_number is 100 7. print current sum Steps 4 and 5 might look odd... how can current sum = current sum + new term? Basically, computers see equals signs (=) differently than how they are used in maths. A computer sees an equals sign as 'assign', so the computer takes the number (like current sum) and replaces it with a new one which is slightly bigger (current sum + new term). Therefore, as the program goes over the steps, the number will get bigger and bigger. Now you can look up in the technical manual for the precise language (also known as syntax) you are using and you can write down the various things above into an actual computer program. Some tips:  Whenever you have to repeat things, look up loops.  Whenever you need to repeat some complicated mathematics over and over again, look up functions.  If there's things that should only work under precise conditions, look up conditionals Here's some code that might work: Code: currentSum = 0; for currentNum = 1:100 currentSum = currentSum + n^2; end fprintf('The sum is: %i \n',currentSum); In any case, I hope this helps! 

Tags 
crisis, help!, octave 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Identity. Crisis.  yogazen2013  Algebra  3  September 6th, 2013 11:50 AM 
Finding the coefficients of a polynomial  Octave  biket  Computer Science  1  January 20th, 2013 10:27 AM 
How to solve * Plot a primitive of sin(x^3). in octave?  MisterT  Calculus  3  December 28th, 2010 01:18 AM 
Finding the coefficients of a polynomial  Octave  biket  Algebra  0  December 31st, 1969 04:00 PM 