diff options
Diffstat (limited to '662/CH9')
-rwxr-xr-x | 662/CH9/EX9.11/example9_11.JPG | bin | 0 -> 28822 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.11/example9_11.sci | 31 | ||||
-rwxr-xr-x | 662/CH9/EX9.12/example9_12.JPG | bin | 0 -> 32070 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.12/example9_12.sci | 37 | ||||
-rwxr-xr-x | 662/CH9/EX9.13/example9_13.JPG | bin | 0 -> 32101 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.13/example9_13.sci | 43 | ||||
-rwxr-xr-x | 662/CH9/EX9.2/example9_2.sci | 19 | ||||
-rwxr-xr-x | 662/CH9/EX9.8/example9_8.JPG | bin | 0 -> 31920 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.8/example9_8.sci | 33 | ||||
-rwxr-xr-x | 662/CH9/EX9.9/example9_9.JPG | bin | 0 -> 22997 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.9/example9_9.sci | 27 |
11 files changed, 190 insertions, 0 deletions
diff --git a/662/CH9/EX9.11/example9_11.JPG b/662/CH9/EX9.11/example9_11.JPG Binary files differnew file mode 100755 index 000000000..3453e3794 --- /dev/null +++ b/662/CH9/EX9.11/example9_11.JPG diff --git a/662/CH9/EX9.11/example9_11.sci b/662/CH9/EX9.11/example9_11.sci new file mode 100755 index 000000000..8507f3f8b --- /dev/null +++ b/662/CH9/EX9.11/example9_11.sci @@ -0,0 +1,31 @@ + //Programming Example 9.11
+ //passing array to function and altering values of array elements
+
+function[] = main()
+ printf("\n From main, before calling the function: \n");
+ for count = 1:3
+ //Here it is 1:3 as in c it starts frm 0 to 2, index 0 is invalid in scilab
+ a(count)=count;
+ printf("a[%d] = %d\n", count, a(count));
+ end
+
+ a= modify(a);
+
+ printf("\nFrom main, after calling the function:\n");
+ for count = 1:3
+ printf("a[%d] = %d\n", count, a(count));
+ end
+endfunction
+
+function[a] = modify(a) //function definition
+ printf("\n From the function, after modifying the values:\n");
+ for count = 1:3
+ a(count)=-9;
+ printf("a[%d] = %d\n", count, a(count));
+ end
+ return a;
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file diff --git a/662/CH9/EX9.12/example9_12.JPG b/662/CH9/EX9.12/example9_12.JPG Binary files differnew file mode 100755 index 000000000..2f0a5c717 --- /dev/null +++ b/662/CH9/EX9.12/example9_12.JPG diff --git a/662/CH9/EX9.12/example9_12.sci b/662/CH9/EX9.12/example9_12.sci new file mode 100755 index 000000000..20698b3a0 --- /dev/null +++ b/662/CH9/EX9.12/example9_12.sci @@ -0,0 +1,37 @@ + //Programming Example 9.12
+ //passing a variable along with an array to the function
+
+a = 1; //global variable
+
+function[] = main()
+ b = 2; //local variable
+ printf("\nFrom main, before calling the function: \n");
+ printf("a = %d b = %d\n", a, b);
+ for count = 1:3
+ c(count) = 10*(count+1);
+ printf("c[%d] = %d\n", count, c(count));
+ end
+
+ c=modify(b,c);
+ printf("\n From main, after calling the function: \n ");
+ printf("a = %d b = %d\n", a, b);
+ for count =1:3
+ printf("c[%d] = %d\n", count, c(count));
+ end
+endfunction
+
+function[c] = modify(b,c) //function definition
+ printf("\n From the function, after modifying the values: \n");
+ a=-999;
+ b=-999;
+ printf("a = %d b = %d\n", a, b);
+ for count =1:3
+ c(count)=-9;
+ printf("c[%d] = %d\n", count, c(count));
+ end
+ return c;
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file diff --git a/662/CH9/EX9.13/example9_13.JPG b/662/CH9/EX9.13/example9_13.JPG Binary files differnew file mode 100755 index 000000000..7ea576cb0 --- /dev/null +++ b/662/CH9/EX9.13/example9_13.JPG diff --git a/662/CH9/EX9.13/example9_13.sci b/662/CH9/EX9.13/example9_13.sci new file mode 100755 index 000000000..6ea97ff18 --- /dev/null +++ b/662/CH9/EX9.13/example9_13.sci @@ -0,0 +1,43 @@ + //Programming Example 9.13
+ //Reorder a 1 dimentional, integer array from smallest to largest
+
+function[] = main()
+ //read in a value for n
+ printf("\n How many numbers will be entered? ");
+ n = scanf("%d");
+ printf("\n");
+
+ //read in the list of numbers
+ for i =1:n
+ printf("i = %d x = ", i+1);
+ x(i) = scanf("%d");
+ end
+
+ //reorder all array elements
+ x=reorder(n,x);
+
+ //display the reordered list of numbers
+ printf("\n\nReordered List of numbers:\n\n");
+ for i=1:n
+ printf("i = %d x=%d\n", i, x(i));
+ end
+endfunction
+
+function[x] = reorder(n, x) //rearrange the list of numbers
+ for item=1:n-1
+ //find the smallest of all remaining elements
+ for i= item+1:n
+ if(x(i) < x(item))
+ //interchange two element
+ temp=x(item);
+ x(item)=x(i);
+ x(i)= temp;
+ end
+ end
+ end
+ return x;
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file diff --git a/662/CH9/EX9.2/example9_2.sci b/662/CH9/EX9.2/example9_2.sci new file mode 100755 index 000000000..9ccb935cf --- /dev/null +++ b/662/CH9/EX9.2/example9_2.sci @@ -0,0 +1,19 @@ + //Programming Example 9.2
+ //Lowercase to Upercase converson using 1 dimensional array
+function[] = main()
+ //read in the line
+ line =input("Enter a line: ","string");
+ SIZE= length(line);
+ for count = 1:1:SIZE
+ letter(count) = part(line, count);
+ end
+ //display the line in upper case
+ for count = 1:1:SIZE
+ a=convstr(letter(count),'u');
+ printf("%c",a);
+ end
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file diff --git a/662/CH9/EX9.8/example9_8.JPG b/662/CH9/EX9.8/example9_8.JPG Binary files differnew file mode 100755 index 000000000..9bdfa3e60 --- /dev/null +++ b/662/CH9/EX9.8/example9_8.JPG diff --git a/662/CH9/EX9.8/example9_8.sci b/662/CH9/EX9.8/example9_8.sci new file mode 100755 index 000000000..94b58422d --- /dev/null +++ b/662/CH9/EX9.8/example9_8.sci @@ -0,0 +1,33 @@ + //Programming Example 9.8
+ //Deviation about an average
+
+function[] = main()
+ Sum=0;
+
+ //read a value for n
+ printf("\nHow many numbers will be averaged? ");
+ n= scanf("%d");
+ printf("\n");
+
+ //read the numbers and calculate their sum
+ for count = 1:1:n
+ printf("i = %d X = ", count);
+ //index count start from 1, so no need to denote it as (count+!) element
+ List(count) = scanf("%f");
+ Sum = Sum+List(count);
+ end
+
+ //calculate and display the average
+ avg = Sum/n;
+ printf("\n The average is %5.2f\n\n", avg);
+
+ //calculate and display the deviations about the average
+ for count = 1:1:n
+ d = List(count)- avg;
+ printf("i = %d X = %5.2f d = %5.2f\n", count, List(count), d);
+ end
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file diff --git a/662/CH9/EX9.9/example9_9.JPG b/662/CH9/EX9.9/example9_9.JPG Binary files differnew file mode 100755 index 000000000..c86689010 --- /dev/null +++ b/662/CH9/EX9.9/example9_9.JPG diff --git a/662/CH9/EX9.9/example9_9.sci b/662/CH9/EX9.9/example9_9.sci new file mode 100755 index 000000000..e82e4efc1 --- /dev/null +++ b/662/CH9/EX9.9/example9_9.sci @@ -0,0 +1,27 @@ + //programming Example 9.9
+//calculate the average of n numbers,
+ //then compute the deviation of each number aboutthe average.
+
+n = 5;
+List={3, -2, 12, 4.4, 3.5};
+
+function[] = main()
+ Sum = 0;
+
+ //calculate and display the average
+ for count = 1:1:n
+ Sum=Sum+List(count);
+ end
+ avg = Sum/n;
+ printf("\nThe average is %5.2f\n\n", avg);
+
+ //Calculate and display the deviations about the average
+ for count = 1:1:n
+ d = List(count)-avg;
+ printf("i = %d X = %5.2f d = %5.2f\n", count, List(count), d);
+ end
+endfunction
+
+//calling main()
+funcprot(0);
+main();
\ No newline at end of file |