SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
I cannot figure out what is going wrong with this MATLAB code. The errors make no sense.
Can someone please tell me what's going wrong?
%Set values displayed in box
defaultWidth = '1';
defaultN = '5';
defaultD = '1';
defaultSigma_a = '0.0001';
defaultSigma_f = '0.01';
defaultn = '1';
defaultS = '1';
defaultk = '1';
defaultRuns = '10';
defaultConv = '0.01';
DH = 0.07;
%Display user variables
prompt = {'Enter slab width:', 'Enter mesh interval amount:', 'Enter diffusion coefficient:', 'Enter
macroscopic absorption cross section:', 'Enter macroscopic fission cross section:', 'Enter neutron
fission ratio:', 'Enter source guess:', 'Enter criticality (k) guess:', 'Enter number of times you wish
the program to run to find convergence:', 'Enter the difference value you consider to determine
convergence:'};
defaultValues = {defaultWidth, defaultN, defaultD, defaultSigma_a, defaultSigma_f, defaultn,
defaultS, defaultk, defaultRuns, defaultConv};
inputValues = inputdlg(prompt, 'Input', 1, defaultValues);
%Store user variables
Width = str2double(inputValues{1});
N = str2double(inputValues{2});
D = str2double(inputValues{3});
Sigma_a = str2double(inputValues{4});
Sigma_f = str2double(inputValues{5});
n = str2double(inputValues{6});
S = str2double(inputValues{7});
k = str2double(inputValues{8});
Runs = str2double(inputValues{9});
Conv = str2double(inputValues{10});
%Calculate constants
delta = Width / N;
aM1 = -D / (delta^2);
a1 = Sigma_a + 2 * (D / (delta^2));
aP1 = -D / (delta^2);
%Load "A"/coefficient matrix
MatDim = N - 1;
Mat = zeros(MatDim, MatDim);
for i = 1:MatDim
for j = 1:MatDim
if j == i - 1 Mat(i,j) = aM1;
elseif j == i Mat(i,j) = a1;
elseif j == i + 1 Mat(i,j) = aP1;
end
end
end
%Calculate source matrix values
Source = zeros(N,1);
Source = Source + S;
%Set a count to track iterations
C = 0;
diff = 1;
while diff > conv && count < Runs
R = Source/k;
Phi = MatR;
new_source = DH*Phi;
%Trapezoidal Estimation
numerator = 0;
denominator = 0;
for i = 1:N-1
numerator = numerator + ((new_source(i) + new_source(i+1))/2)*delta;
denominator = denominator + ((S(i) + S(i+1))/2) *delta;
end
denominator;
numerator;
k_new = numerator/(denominator*(k^-1));
diff = abs((k_new - k)/k_new);
k = k_new;
S = new_source;
C = C+1;
end
disp(k_new);
disp(C);

Weitere ähnliche Inhalte

Ähnlich wie I cannot figure out what is going wrong with this MATLAB code. The e.pdf

BIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using MatlabBIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using Matlab
Shiv Koppad
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
Abi finni
 
C programs
C programsC programs
C programs
Minu S
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
jacksnathalie
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Kumpulan contoh-program-pascal
Kumpulan contoh-program-pascalKumpulan contoh-program-pascal
Kumpulan contoh-program-pascal
rey25
 

Ähnlich wie I cannot figure out what is going wrong with this MATLAB code. The e.pdf (20)

BIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using MatlabBIometrics- plotting DET and EER curve using Matlab
BIometrics- plotting DET and EER curve using Matlab
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
C programs
C programsC programs
C programs
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
 
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชันตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Programming egs
Programming egs Programming egs
Programming egs
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Majorana zero modes
Majorana zero modesMajorana zero modes
Majorana zero modes
 
verilog code
verilog codeverilog code
verilog code
 
Matlab programs
Matlab programsMatlab programs
Matlab programs
 
Kumpulan contoh-program-pascal
Kumpulan contoh-program-pascalKumpulan contoh-program-pascal
Kumpulan contoh-program-pascal
 
Kumpulan program pascal
Kumpulan program pascalKumpulan program pascal
Kumpulan program pascal
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
nn network
nn networknn network
nn network
 

Mehr von pratyushraj61

I need help getting my code to work (code is at the bottom)1.3.pdf
I need help getting my code to work (code is at the bottom)1.3.pdfI need help getting my code to work (code is at the bottom)1.3.pdf
I need help getting my code to work (code is at the bottom)1.3.pdf
pratyushraj61
 
I need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdfI need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdf
pratyushraj61
 
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdfI need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
pratyushraj61
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
pratyushraj61
 

Mehr von pratyushraj61 (20)

helphelp Regarding the numerou.pdf
helphelp Regarding the numerou.pdfhelphelp Regarding the numerou.pdf
helphelp Regarding the numerou.pdf
 
Hello. Im having trouble trying to set the condition where once the .pdf
Hello. Im having trouble trying to set the condition where once the .pdfHello. Im having trouble trying to set the condition where once the .pdf
Hello. Im having trouble trying to set the condition where once the .pdf
 
Henrich is a single taxpayer. In 2022, his taxable income is $478,0.pdf
Henrich is a single taxpayer.  In 2022, his taxable income is $478,0.pdfHenrich is a single taxpayer.  In 2022, his taxable income is $478,0.pdf
Henrich is a single taxpayer. In 2022, his taxable income is $478,0.pdf
 
Hi could you focus on the isohyetal method and thiessen polygon me.pdf
Hi could you focus on the isohyetal method and thiessen polygon me.pdfHi could you focus on the isohyetal method and thiessen polygon me.pdf
Hi could you focus on the isohyetal method and thiessen polygon me.pdf
 
helpppppp((( The difference between an embedded object and a linked.pdf
helpppppp((( The difference between an embedded object and a linked.pdfhelpppppp((( The difference between an embedded object and a linked.pdf
helpppppp((( The difference between an embedded object and a linked.pdf
 
help on this thanks. Phalaropes are shore birds with brightly col.pdf
help on this thanks.  Phalaropes are shore birds with brightly col.pdfhelp on this thanks.  Phalaropes are shore birds with brightly col.pdf
help on this thanks. Phalaropes are shore birds with brightly col.pdf
 
I have an independent food delivery platform having a lot of differe.pdf
I have an independent food delivery platform having a lot of differe.pdfI have an independent food delivery platform having a lot of differe.pdf
I have an independent food delivery platform having a lot of differe.pdf
 
i need programingi need programing ai. Create o Va opplication t.pdf
i need programingi need programing ai. Create o Va opplication t.pdfi need programingi need programing ai. Create o Va opplication t.pdf
i need programingi need programing ai. Create o Va opplication t.pdf
 
I need help with making a program that can be part of a google forms.pdf
I need help with making a program that can be part of a google forms.pdfI need help with making a program that can be part of a google forms.pdf
I need help with making a program that can be part of a google forms.pdf
 
I need help fixing my assembly program please, I keep getting a segm.pdf
I need help fixing my assembly program please, I keep getting a segm.pdfI need help fixing my assembly program please, I keep getting a segm.pdf
I need help fixing my assembly program please, I keep getting a segm.pdf
 
I need help getting my code to work (code is at the bottom)1.3.pdf
I need help getting my code to work (code is at the bottom)1.3.pdfI need help getting my code to work (code is at the bottom)1.3.pdf
I need help getting my code to work (code is at the bottom)1.3.pdf
 
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdfHewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
Hewitt Packaging Companynin �denmemi 14 kupon faiz oranyla 1.000 A.pdf
 
I need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdfI need an explanation on what the function of the number 1.428 in .pdf
I need an explanation on what the function of the number 1.428 in .pdf
 
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdfI need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
 
I need help being able to enable different voting types such as publ.pdf
I need help being able to enable different voting types such as publ.pdfI need help being able to enable different voting types such as publ.pdf
I need help being able to enable different voting types such as publ.pdf
 
I have this Koch Python code but isnt working. Can some please revi.pdf
I have this Koch Python code but isnt working. Can some please revi.pdfI have this Koch Python code but isnt working. Can some please revi.pdf
I have this Koch Python code but isnt working. Can some please revi.pdf
 
How do zoned reserves manage relations with local people1. Zone.pdf
How do zoned reserves manage relations with local people1. Zone.pdfHow do zoned reserves manage relations with local people1. Zone.pdf
How do zoned reserves manage relations with local people1. Zone.pdf
 
I have included the person.h file code. 1-4 In a file called functio.pdf
I have included the person.h file code. 1-4 In a file called functio.pdfI have included the person.h file code. 1-4 In a file called functio.pdf
I have included the person.h file code. 1-4 In a file called functio.pdf
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
 
I have a question regarding extreme value analysis.I fitted a gene.pdf
I have a question regarding extreme value analysis.I fitted a gene.pdfI have a question regarding extreme value analysis.I fitted a gene.pdf
I have a question regarding extreme value analysis.I fitted a gene.pdf
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

I cannot figure out what is going wrong with this MATLAB code. The e.pdf

  • 1. I cannot figure out what is going wrong with this MATLAB code. The errors make no sense. Can someone please tell me what's going wrong? %Set values displayed in box defaultWidth = '1'; defaultN = '5'; defaultD = '1'; defaultSigma_a = '0.0001'; defaultSigma_f = '0.01'; defaultn = '1'; defaultS = '1'; defaultk = '1'; defaultRuns = '10'; defaultConv = '0.01'; DH = 0.07; %Display user variables prompt = {'Enter slab width:', 'Enter mesh interval amount:', 'Enter diffusion coefficient:', 'Enter macroscopic absorption cross section:', 'Enter macroscopic fission cross section:', 'Enter neutron fission ratio:', 'Enter source guess:', 'Enter criticality (k) guess:', 'Enter number of times you wish the program to run to find convergence:', 'Enter the difference value you consider to determine convergence:'}; defaultValues = {defaultWidth, defaultN, defaultD, defaultSigma_a, defaultSigma_f, defaultn, defaultS, defaultk, defaultRuns, defaultConv}; inputValues = inputdlg(prompt, 'Input', 1, defaultValues); %Store user variables Width = str2double(inputValues{1}); N = str2double(inputValues{2}); D = str2double(inputValues{3}); Sigma_a = str2double(inputValues{4}); Sigma_f = str2double(inputValues{5}); n = str2double(inputValues{6}); S = str2double(inputValues{7}); k = str2double(inputValues{8}); Runs = str2double(inputValues{9}); Conv = str2double(inputValues{10}); %Calculate constants
  • 2. delta = Width / N; aM1 = -D / (delta^2); a1 = Sigma_a + 2 * (D / (delta^2)); aP1 = -D / (delta^2); %Load "A"/coefficient matrix MatDim = N - 1; Mat = zeros(MatDim, MatDim); for i = 1:MatDim for j = 1:MatDim if j == i - 1 Mat(i,j) = aM1; elseif j == i Mat(i,j) = a1; elseif j == i + 1 Mat(i,j) = aP1; end end end %Calculate source matrix values Source = zeros(N,1); Source = Source + S; %Set a count to track iterations C = 0; diff = 1; while diff > conv && count < Runs R = Source/k; Phi = MatR; new_source = DH*Phi; %Trapezoidal Estimation numerator = 0; denominator = 0; for i = 1:N-1 numerator = numerator + ((new_source(i) + new_source(i+1))/2)*delta; denominator = denominator + ((S(i) + S(i+1))/2) *delta; end denominator; numerator; k_new = numerator/(denominator*(k^-1)); diff = abs((k_new - k)/k_new);
  • 3. k = k_new; S = new_source; C = C+1; end disp(k_new); disp(C);