Permalink
Browse files

problem 101

  • Loading branch information...
1 parent ce652cd commit c3656c8b768c07974861379697dc48ea05f01b30 @tingleshao committed Jun 6, 2013
@@ -0,0 +1,12 @@
+function [ A ] = construct_A( n )
+%CONSTRUCT_A Summary of this function goes here
+% Detailed explanation goes here
+for i = 1 : n
+ for j = 1 : n
+ A(i,j) = i^(j-1);
+ end
+end
+
+
+end
+
@@ -0,0 +1,9 @@
+function [ c ] = construct_C( n )
+%CONSTRUCT_C Summary of this function goes here
+% Detailed explanation goes here
+for i = 1:n-1
+ c(i) = n^(i-1);
+end
+
+end
+
@@ -0,0 +1,18 @@
+clear
+for i = 1:10
+ a(i) = u_n(i)
+end
+
+a
+% construct A matrix
+sum_fit = 0;
+for i = 1:10,
+ A = construct_A(i);
+ y = a(1:i)';
+ b = A\y;
+ c = construct_C(i+1);
+ fit = (c * b);
+ sum_fit = sum_fit + fit;
+end
+sum_fit
+
@@ -1,2 +1,7 @@
# problem 101
+def un(x):
+ return 1 - x + x**2 - x **3 + x **4 - x **5 + x **6 - x **7 + x ** 8- x **9 + x ** 10
+
+for i in range(1,11):
+ print un(i)
View
@@ -0,0 +1,4 @@
+function [x] = u_n(n)
+ x = 1 - n + n^2 - n^3 + n^4 - n^5 + n^6 - n^7 + n^8 - n^9 + n^10;
+
+end

0 comments on commit c3656c8

Please sign in to comment.