SlideShare a Scribd company logo
1 of 2
%%% Solve non-linear ODE u''-u^2 = f(x), u(0)=u(1)=0; f=-sin(x)-
sin(x)^2
close all; clear all;
m = 40; h=pi/m; N=m-1;
x=0:h:pi; x=x'; ue=sin(x); % mesh and true soln
uc = x.*(pi -x); % initial guess:
b = -sin(x) - sin(x).^2; % right hand side
plot(x,uc)
%title('initial guess')
pause(2)
hold on
u1=uc(2:m); F=b(2:m); % Take off two BC
e = ones(N,1); R=e; % initial set-up
tol = 1.e-8; err = 10.0;
% begin iterations of Newton's method:
k = 0; kmax=1000;
while err > tol & k <kmax
for i=1:N
jac(i,i)=-2*(1+h^2*u1(i))/h^2; % Jacobian diagonals.
R(i) = (uc(i)-2*uc(i+1)-(h*uc(i+1))^2+uc(i+2))/h^2 - F(i);
end
for i=1:N-1
jac(i,i+1) = 1/h^2; jac(i+1,i)=1/h^2; % Jacobian off diagonals.
end
delta = -jacR;
u2 = u1 + delta;
k = k + 1;
err = max(abs(u2-u1))
u1 = u2;
uc=[0
u2
0];
plot(x,uc)
end
set(gca,'FontSize',18);
set(0,'DefaulttextFontSize',18)
max(abs(uc-ue))
figure(2); plot(x,uc,x,ue)
title('Final and computed solution')
figure(3); plot(x,uc-ue)
title('The error')
k % Show number of iterations.

More Related Content

What's hot

Numerical methods course project report
Numerical methods course project reportNumerical methods course project report
Numerical methods course project reportZeeshan Ali
 
Stat 101 formulae sheet
Stat 101   formulae sheetStat 101   formulae sheet
Stat 101 formulae sheetSamiya Yesmin
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorAbhranil Das
 
Trapezoidal log log
Trapezoidal log logTrapezoidal log log
Trapezoidal log logPatrick Hui
 
Inflexion point
Inflexion pointInflexion point
Inflexion pointSufyan712
 
Forced Vibrations Project
Forced Vibrations ProjectForced Vibrations Project
Forced Vibrations ProjectMark Falcone
 
Continuity and differentiation
Continuity and differentiationContinuity and differentiation
Continuity and differentiationDr. Hari Arora
 
Queuing theory : Notes
Queuing theory : NotesQueuing theory : Notes
Queuing theory : NotesSubhajit Sahu
 
Sistemas de dos ecuacioneslineales
Sistemas de dos ecuacioneslinealesSistemas de dos ecuacioneslineales
Sistemas de dos ecuacioneslinealesVictor Alegre
 
Queuing theory 1 : Notes
Queuing theory 1 : NotesQueuing theory 1 : Notes
Queuing theory 1 : NotesSubhajit Sahu
 
Identidades trigonometricas
Identidades trigonometricasIdentidades trigonometricas
Identidades trigonometricasNumael Sanchez
 
M3 16marks
M3 16marksM3 16marks
M3 16marksvembbu
 

What's hot (18)

Rolle's theorem
Rolle's theorem Rolle's theorem
Rolle's theorem
 
Numerical methods course project report
Numerical methods course project reportNumerical methods course project report
Numerical methods course project report
 
Stat 101 formulae sheet
Stat 101   formulae sheetStat 101   formulae sheet
Stat 101 formulae sheet
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel Oscillator
 
Matlab code for secant method
Matlab code for secant methodMatlab code for secant method
Matlab code for secant method
 
Trapezoidal log log
Trapezoidal log logTrapezoidal log log
Trapezoidal log log
 
Inflexion point
Inflexion pointInflexion point
Inflexion point
 
Forced Vibrations Project
Forced Vibrations ProjectForced Vibrations Project
Forced Vibrations Project
 
Regula falsi MATLAB Code
Regula falsi MATLAB CodeRegula falsi MATLAB Code
Regula falsi MATLAB Code
 
Continuity and differentiation
Continuity and differentiationContinuity and differentiation
Continuity and differentiation
 
Queuing theory : Notes
Queuing theory : NotesQueuing theory : Notes
Queuing theory : Notes
 
Sistemas de dos ecuacioneslineales
Sistemas de dos ecuacioneslinealesSistemas de dos ecuacioneslineales
Sistemas de dos ecuacioneslineales
 
Queuing theory 1 : Notes
Queuing theory 1 : NotesQueuing theory 1 : Notes
Queuing theory 1 : Notes
 
Calc 3.4
Calc 3.4Calc 3.4
Calc 3.4
 
Alg2 lesson 6-1
Alg2 lesson 6-1Alg2 lesson 6-1
Alg2 lesson 6-1
 
scientific computing
scientific computingscientific computing
scientific computing
 
Identidades trigonometricas
Identidades trigonometricasIdentidades trigonometricas
Identidades trigonometricas
 
M3 16marks
M3 16marksM3 16marks
M3 16marks
 

Similar to Prg

Use the same variable names and write the function F - Force(x-ks-kc-l.pdf
Use the same variable names and write the function F - Force(x-ks-kc-l.pdfUse the same variable names and write the function F - Force(x-ks-kc-l.pdf
Use the same variable names and write the function F - Force(x-ks-kc-l.pdfacteleshoppe
 
graphs plotting in MATLAB
graphs plotting in MATLABgraphs plotting in MATLAB
graphs plotting in MATLABApurva Patil
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdfasenterprisestyagi
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plottingAmr Rashed
 
Computational Method to Solve the Partial Differential Equations (PDEs)
Computational Method to Solve the Partial Differential  Equations (PDEs)Computational Method to Solve the Partial Differential  Equations (PDEs)
Computational Method to Solve the Partial Differential Equations (PDEs)Dr. Khurram Mehboob
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
dynamical analysis of soil and structures
dynamical analysis of soil and structuresdynamical analysis of soil and structures
dynamical analysis of soil and structuresHaHoangJR
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processingaj ahmed
 
Application of Differential Equation
Application of Differential EquationApplication of Differential Equation
Application of Differential EquationMayank Velani
 
Convolution_System_Response
Convolution_System_ResponseConvolution_System_Response
Convolution_System_ResponseMatthew Mobley
 

Similar to Prg (20)

Use the same variable names and write the function F - Force(x-ks-kc-l.pdf
Use the same variable names and write the function F - Force(x-ks-kc-l.pdfUse the same variable names and write the function F - Force(x-ks-kc-l.pdf
Use the same variable names and write the function F - Force(x-ks-kc-l.pdf
 
graphs plotting in MATLAB
graphs plotting in MATLABgraphs plotting in MATLAB
graphs plotting in MATLAB
 
Please use the same variables and only write the TODO part #!-usr-bi.pdf
Please use the same variables and only write the TODO part   #!-usr-bi.pdfPlease use the same variables and only write the TODO part   #!-usr-bi.pdf
Please use the same variables and only write the TODO part #!-usr-bi.pdf
 
assignment_2
assignment_2assignment_2
assignment_2
 
Ma2002 1.16 rm
Ma2002 1.16 rmMa2002 1.16 rm
Ma2002 1.16 rm
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Computational Method to Solve the Partial Differential Equations (PDEs)
Computational Method to Solve the Partial Differential  Equations (PDEs)Computational Method to Solve the Partial Differential  Equations (PDEs)
Computational Method to Solve the Partial Differential Equations (PDEs)
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
 
Simple harmonic motion1
Simple harmonic motion1Simple harmonic motion1
Simple harmonic motion1
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
dynamical analysis of soil and structures
dynamical analysis of soil and structuresdynamical analysis of soil and structures
dynamical analysis of soil and structures
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
Application of Differential Equation
Application of Differential EquationApplication of Differential Equation
Application of Differential Equation
 
05_AJMS_332_21.pdf
05_AJMS_332_21.pdf05_AJMS_332_21.pdf
05_AJMS_332_21.pdf
 
Sary
SarySary
Sary
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Adaptive signal processing simon haykins
Adaptive signal processing simon haykinsAdaptive signal processing simon haykins
Adaptive signal processing simon haykins
 
Sect5 1
Sect5 1Sect5 1
Sect5 1
 
Ma2002 1.14 rm
Ma2002 1.14 rmMa2002 1.14 rm
Ma2002 1.14 rm
 
Convolution_System_Response
Convolution_System_ResponseConvolution_System_Response
Convolution_System_Response
 

Recently uploaded

Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...ThinkInnovation
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangeThinkInnovation
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numberssuginr1
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...HyderabadDolls
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxAniqa Zai
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...gajnagarg
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...SOFTTECHHUB
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxchadhar227
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareGraham Ware
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRajesh Mondal
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...nirzagarg
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...HyderabadDolls
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...vershagrag
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraGovindSinghDasila
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowgargpaaro
 

Recently uploaded (20)

Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptx
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 

Prg

  • 1. %%% Solve non-linear ODE u''-u^2 = f(x), u(0)=u(1)=0; f=-sin(x)- sin(x)^2 close all; clear all; m = 40; h=pi/m; N=m-1; x=0:h:pi; x=x'; ue=sin(x); % mesh and true soln uc = x.*(pi -x); % initial guess: b = -sin(x) - sin(x).^2; % right hand side plot(x,uc) %title('initial guess') pause(2) hold on u1=uc(2:m); F=b(2:m); % Take off two BC e = ones(N,1); R=e; % initial set-up tol = 1.e-8; err = 10.0; % begin iterations of Newton's method: k = 0; kmax=1000; while err > tol & k <kmax
  • 2. for i=1:N jac(i,i)=-2*(1+h^2*u1(i))/h^2; % Jacobian diagonals. R(i) = (uc(i)-2*uc(i+1)-(h*uc(i+1))^2+uc(i+2))/h^2 - F(i); end for i=1:N-1 jac(i,i+1) = 1/h^2; jac(i+1,i)=1/h^2; % Jacobian off diagonals. end delta = -jacR; u2 = u1 + delta; k = k + 1; err = max(abs(u2-u1)) u1 = u2; uc=[0 u2 0]; plot(x,uc) end set(gca,'FontSize',18); set(0,'DefaulttextFontSize',18) max(abs(uc-ue)) figure(2); plot(x,uc,x,ue) title('Final and computed solution') figure(3); plot(x,uc-ue) title('The error') k % Show number of iterations.