Question

Use the difference equation wi,j+1 = 120;+1,j + 2(1 – 12); +120;-1,j - Ui,j-1 to approximate the solution of the boundary-val

Use a computer as a computational aid with code that is able to paste.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB CODE FOR BVP

function [M]= BVP(problem)

if problem==1
c=1;a=1;T=1;n=4;m=20;
f=@(x)(x.*(x-1)); %initial condion problem 1
x=linspace(0,a,m );
u_t0=f(x); % using initial condition
end
if problem==2
c=1;a=2;T=1;n=5;m=20;
f=@(x)(exp(-18*(x-1)^2)); %initial condion problem 2
x=linspace(0,a,m );
u_t0=f(x); % using initial condition
end
if problem==3
c=sqrt(2);a=1;T=1;n=10;m=50;
x=linspace(0,a,m );
u_t0=problem3_ini(x); % using initial condition
end
M=zeros(m,n);
u_BC=[0,0];%Boundary condition

  
A=sparse(m);B=sparse(m,1); % for solving system
t=linspace(0,T,n); % discretising domain in given number of points
% A(1,1)=1;A(m,m)=1;B(1,1)=0;B(m,1)=0; % By using BC
dx=x(2)-x(1);dt=t(2)-t(1); lamda=(dt)^2/(dx)^2;

M(1:end,1)=u_t0
% we use initial velocity du/dx=0 at t=0
u_t1=u_t0;
M(1:end,2)=u_t0
for N=3:1:length(t)
A(1,1)=1;A(m,m)=1;B(1,1)=0;B(m,1)=0; % By using BC
for i=2:1:length(x)-1
A(i,i)=1; % by given difference equation
B(i)=lamda^2*c^2*(u_t1(i+1)-2*u_t1(i)+u_t1(i-1))+2*u_t1(i)-u_t0(i);% by given difference equation
end
u_t2=A\B;
M(1:end,N)=u_t2;
u_t0=u_t1; % updating previous time solution
u_t1=u_t2;% updating previous time solution

  
  
end
double(M)
end

function u=problem3_ini(x)
u=zeros(length(x),1);
for i=1:1:length(x)
if x(i)>0.5
u(i)=0.6;
else
u(i)=0;
end
end
end

Results  

Above function take the value problem no. 1 for (a), 2 for (b) 3 for (c). and return the solution matrix in which column denote the time step solution and row represents the solution at each space steps on same time. there is a function problem3_ini need to save in the same file where we are saving BVP since we are calling this function in BVP for calculating initial condition for problem 3.

BVP(1)

ans =

1.0e+04 *

0 0 0 0
-0.0000 -0.0000 0.0009 -1.4314
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 -1.4314
0 0 0 0

ans =

1.0e+04 *

0 0 0 0
-0.0000 -0.0000 0.0009 -1.4314
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0026
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 0.0027
-0.0000 -0.0000 0.0009 -1.4314
0 0 0 0

  

>> BVP(3)

ans =

1.0e+27 *

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0.0002
0 0 0 0 0 0 0 0 0.0000 -0.0032
0 0 0 0 0 0 0 0.0000 -0.0000 0.0223
0 0 0 0 0 0 0.0000 -0.0000 0.0000 -0.0967
0 0 0 0 0 0.0000 -0.0000 0.0000 -0.0001 0.2899
0 0 0 0 0.0000 -0.0000 0.0000 -0.0000 0.0002 -0.6375
0 0 0 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0003 1.0621
0 0 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0004 -1.3653
0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0004 1.3653
0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0003 -1.0621
0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0002 0.6375
0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0001 -0.2899
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0967
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0223
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0032
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0002
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0001
0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0001
0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0001
0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0001
0.0000 0.0000 0 0 0 0 0 0 0 0

>>


  

Add a comment
Know the answer?
Add Answer to:
Use a computer as a computational aid with code that is able to paste. Use the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer the question (d), (e), (f). 11. (12 points, 2 points each) Find the computational...

    Please answer the question (d), (e), (f). 11. (12 points, 2 points each) Find the computational complexity for the following code fragments: (a Nyhoff p. 364 Drozdek pp. 72-73, f Weiss, p. 72) a. for (int x = 1, count = 0, 1-0; i < n; i++) for (int j 0; j <= x; j++) counttti x = 2; b. for (int count 0, i = 0; i < n; i++) for (int j = 0; j < n; j++)...

  • a) Use MATLAB to find the Fourier Transform F(w) of the following function f(t). b) Plot...

    a) Use MATLAB to find the Fourier Transform F(w) of the following function f(t). b) Plot F(w). Express the x-axis in [Hz]. Plot for f = -8Hz to 8Hz. f(t) = cos(27 (34))e-**" 0.8 0.6 0.4 0.2 f(t) appears to oscillate at 3 cycles/sec 0 -0.2 -0.4 -0.6 0.8 -1 2 -1.5 -0.5 0 0.5 1 1.5 2

  • 2. (35P) Ashell-and-tube heat exchanger with 1-shell pass and 20-tube passes is used to heat glycerin...

    2. (35P) Ashell-and-tube heat exchanger with 1-shell pass and 20-tube passes is used to heat glycerin (Cp = 2480 J/kg) in the shell, with hot water in the tubes. The tubes are thinwalled and have a diameter of 1.5 cm and length of 2 m per pass. The hot water (Cp=4180 J/kg Centers the tubes at 102°C at a rate of 9 kg/s and leaves at 55°C. Overall heat transfer coefficient U=13900 W/m2C. The glycerin enters the shell at 15°C...

  • Classify the following signals below. For each signal provide a brief discussion about the conclusions presented:...

    Classify the following signals below. For each signal provide a brief discussion about the conclusions presented: - Does the signal have energy, power, or neither? - Is the signal Deterministic or random? t sin(200nt) x[n] = ein A B 60 250 40 200 20 150 0 um w 100 -20 50 -40 1-15 -10 -5 0 5 10 0 -50 5 0 50 C D 1 0.8 0.5 0.6 Lilar lolit 0.4 0 0.2 m 0 -0.5 -0.2 0.4 -0.6...

  • Please explain the python code below L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42,...

    Please explain the python code below L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42, 27, -1, 2.0, 'hello', [2, 4], 23] print("L1 =",L1) odds =[] evens=[] list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',',','.'] no=0 for i in L1: i=str(i) for j in list: if i.find(j)>=0: no=1 if no==1: None else: i=int(i) if i%2==0: evens.append(i) else: odds.append(i) no=0      ...

  • I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear...

    I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear all; format long; f=@(t,y)y*(1-y); y(1)=0.01; %%%% Exact solution [t1 y1]=ode45(f,[0 9],y(1)); figure; plot(t1,y1,'*'); hold on % Eular therom M=[32 64 128]; T=9; fprintf(' M Max error \n' ); for n=1:length(M) k=T/M(n); t=0:k:T; for h=1:length(t)-1 y(h+1)=y(h)+k*f(t(h),y(h)); end plot(t,y); hold on %%%...

  • Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 1...

    Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 100 #define maxint 10000 void dijkstra(int n,int v,int dist[],int prev[],int c[][NUM]) {    int i,j;    bool s[NUM];    for(i=1; i<=n; i++)    {        dist[i] = c[v][i];        s[i] = false;        if (dist[i]>maxint) prev[i] = 0;        else prev[i] = v;    }    dist[v] = 0;    s[v] = true;    for(i=1; i<n; i++)    {        int tmp = maxint;        int u = v;        for(j=1; j<=n; j++)            if(!(s[j]) && (dist[j]<tmp))            {                u = j;                tmp = dist[j];           ...

  • % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root...

    % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root of a function f(x) in the interval [a, b] using the Bisection method % % It uses f.m to define f(x), and assumes f(x) is continuous % It requires specification of a, b and the maximum error % It defines error using |f(xnew)| % Define inputs for problem a=0; %Defines lower limit of initial bracketing interval b=1; %Defines upper limit of initial bracketing interval...

  • Please do not use SYMS package. It does not work on Octave for me. Matlab code...

    Please do not use SYMS package. It does not work on Octave for me. Matlab code needed for: 1. Apply the Explicit Trapezoid Method on a grid of step size h = 0.1 in [0, 1] to the initial value problems in Exercise 1. Print a table of the t values, approximations, and global truncation error at each step. IVP (Exercise 1): (a) y'=1 (b) y' = 12y (c) y' = 2(t+1)y (d) y = 564, (e) y'=1/y² (1) y'=1/y2...

  • The mass of uniform bar ABC is MBAR = 30 kg and its overall length is...

    The mass of uniform bar ABC is MBAR = 30 kg and its overall length is L=1.6 m. The bar rotates around point 0 and force F(t) is being to the end of the bar at C. The masses of pistons A and B are ma = 5 kg and mg = 8 kg , respectively. k= 20000 N/m for each spring and c=500 N-s/m for the damper connected to piston A. Coordinate e locates the bar, coordinate x, locates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT