Stay up to date – embedded code automagically updates, each snippet and article has a feed
Join Siafoo Now
or
Learn More
Euclidian Norm
Updated 7 months ago (04 Feb 2010 at 08:18 PM)
recent activity
| In Brief | Finds the euclidian norm of a matrix you specify. |
| Language | C |
# 's
1/* Programmed by David Isaacson, 2003
2 * Released into the Public Domain
3 *
4 * euclidiannorm.c
5 *
6 * This program will find the euclidian norm of a matrix A
7 */
8
9#include<stdio.h>
10#include<math.h>
11
12int main()
13{
14 int i,j; //counters
15 int columns,rows; //columns and rows of A
16 double value; //value of A(i,j)
17 double sum=0; //sum of the squares
18 double norm; //just what it looks like
19
20 printf("This program will find the Euclidian Norm of a matrix you specify.\n");
21 printf("How many rows are in the matrix? ");
22 scanf("%i",&rows);
23 printf("How many columns? ");
24 scanf("%i",&columns);
25
26 //time to input A - we don't need to bother remembering the values, though
27 for(i=1;i<=rows;i++)
28 {
29 for(j=1;j<=columns;j++)
30 {
31 printf("What is the value at %i,%i? ",i,j);
32 scanf("%lf",&value);
33 sum+=value*value; //adding the square of the value
34 //to the total sum
35 }
36 }
37 //now we have the sum of all the squares
38
39 norm=sqrt(sum); //duh
40
41 printf("The euclidian norm of your matrix is: %lf\n",norm);
42
43 return 0;
44}
Finds the euclidian norm of a matrix you specify.
Add a Comment