Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Problem 6
  • Loading branch information
nin13001 committed Nov 18, 2017
1 parent af13436 commit 508aeaf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Expand Up @@ -274,3 +274,55 @@ legend('data','linear','pchip','spline')

Plot
![](assets/README-93e4eb4a.png)

# Problem 6

Analytical Solution

```
fun = @(x) (1/6).*(x).^3+(1/2).*(x).^2+(x);
q = integral(fun,2,3)
```

Gaussian Method

```
%1-Pt
x = [0];
a = [2];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value1 = sum(tildec.*f)
%2-Pt
x = [-0.57735,0.57735];
a = [1,1];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value2 = sum(tildec.*f)
%3-Pt
x = [-0.77459666,0,0.77459666];
a = [0.5555555,0.88888888,0.55555555];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value3 = sum(tildec.*f)
```

Outputs
| Method | Value | Error |
| ------------- | ------------- |-------------|
| Analytical | 8.375 | 0% |
| Gaussian 1-Pt | 8.2292 | 1% |
| Gaussian 2-Pt | 8.375 | 0% |
| Gaussian 3-Pt | 8.375 | 0% |
2 changes: 2 additions & 0 deletions analyticalprob6.m
@@ -0,0 +1,2 @@
fun = @(x) (1/6).*(x).^3+(1/2).*(x).^2+(x);
q = integral(fun,2,3)
30 changes: 30 additions & 0 deletions gaussianprob6.m
@@ -0,0 +1,30 @@
%1-Pt
x = [0];
a = [2];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value1 = sum(tildec.*f)

%2-Pt
x = [-0.57735,0.57735];
a = [1,1];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value2 = sum(tildec.*f)


%3-Pt
x = [-0.77459666,0,0.77459666];
a = [0.5555555,0.88888888,0.55555555];
b = 2;
c = 3;
tildec = (c-b)/2*a;
tildex = (c-b)/2*x + (c+b)/2;
f = (1/6).*(tildex).^3+(1/2).*(tildex).^2+(tildex);
value3 = sum(tildec.*f)

0 comments on commit 508aeaf

Please sign in to comment.