Troubleshooting PDE Code for a Pricing Model: Help Needed!

  • Thread starter xuej1112
  • Start date
  • Tags
    Code Pde
In summary, there are a few things that could be causing issues with your code and results. Suggestions for troubleshooting and improving your model include checking initial and boundary conditions, using proper variable names, double checking equations and units, using vectorization, testing with simple inputs, and utilizing debugging tools. These steps should help you fix any errors and improve the accuracy of your pricing model.
  • #1
xuej1112
18
0
I make a pricing model as the attachment and write the code as the following,but there are something wrong in the result.Who could help me to check it?!
Thx so much!
View attachment Microsoft Word .doc
the code:
>> dr = 0.005;
Nr = 20;
dt = 0.01;
Nt = 1/dt;
a=0.2339*0.0189;
b=0.2339;
delta=sqrt(0.0073);
T = zeros(Nr+1,Nt+1);
time = [0:12/Nt:12];
T(:,1) = 1;
maxiter = 500
for iter = 1:maxiter
for i=2:Nt+1

T(1,i)=(1-a*dt/dr)*T(1,i-1)+(a*dt/dr)*T(2,i-1);
for j=2:Nr
%depth_2D = (T(1:end-2,i-1)-2*T(2:end-1,i-1)+T(3:end,i-1))/dz^2;
depth_2D = (delta^2/(2*dr^2)*dr*(j-1)+((a-b)*dr*(j-1))/(2*dr))*T(j-1,i-1)-(delta^2/(dr^2)*dr*(j-1)+dr*(j-1))*T(j,i-1)+(delta^2/(2*dr^2)*dr*(j-1)+((a-b)*dr*(j-1))/(2*dr))*T(j+1,i-1);
time_1D = depth_2D;
T(j,i) = time_1D*dt + T(j,i-1);
end
T(Nr+1,i) = T(Nr+1-1,i);

end
%end
err(iter) = min(abs(T(:)-0.5)); %Find difference between last two solutions
if err(iter)<1E-4
break; % Stop if solutions very similar, we have convergence
end
end
if iter==maxiter;
warning('Convergence not reached')
end
 
Last edited:
Physics news on Phys.org
  • #2



There are a few things that could be causing issues with your code and results. Here are some suggestions to help you troubleshoot and improve your model:

1. Check your initial conditions: The initial condition for depth_2D is not properly defined. It should be equal to the temperature at the previous time step, which is T(j,i-1). Make sure to update this in your code.

2. Check your boundary conditions: The boundary condition for T(Nr+1,i) is not correct. It should be equal to T(Nr,i) instead of T(Nr-1,i).

3. Use proper variable names: It is always a good practice to use meaningful variable names that are easy to understand and follow. This will also help you to avoid errors and confusion in your code.

4. Check your equations: Make sure you have written the equations correctly and have accounted for all the necessary terms and parameters. Double check your calculations and units to ensure they are consistent.

5. Use vectorization: Instead of using for loops, try to vectorize your code as much as possible. This will improve the efficiency and accuracy of your model.

6. Test your code with simple inputs: Before running your code with complex inputs, try testing it with simple inputs and known solutions to see if you are getting the expected results.

7. Use debugging tools: Most programming languages have debugging tools that can help you identify errors and track the flow of your code. Use these tools to find and fix any issues in your code.

I hope these suggestions will help you improve your pricing model and get the correct results. Good luck!
 

1. What is a PDE?

A PDE, or partial differential equation, is a type of mathematical equation that describes how a quantity or function changes in multiple dimensions. It is commonly used in physics and engineering to model complex systems.

2. How do I solve a PDE?

Solving a PDE involves finding a function or set of functions that satisfy the given equation. This can be done analytically, using mathematical techniques, or numerically, using computational methods.

3. What are some common techniques for solving PDEs?

Some common techniques for solving PDEs include separation of variables, the method of characteristics, and finite difference or finite element methods.

4. Can PDEs be used to model real-world problems?

Yes, PDEs can be used to model a wide range of real-world problems, including heat transfer, fluid flow, and electromagnetic fields. They are also used in economics, biology, and other fields to understand complex systems.

5. Are there any software programs that can help me solve PDEs?

Yes, there are many software programs available that can help with solving PDEs. Some popular options include MATLAB, COMSOL, and Mathematica. These programs use numerical methods to solve PDEs and can handle a wide range of equations and boundary conditions.

Similar threads

  • Differential Equations
Replies
2
Views
2K
  • Differential Equations
Replies
1
Views
770
  • Differential Equations
Replies
23
Views
4K
Replies
1
Views
1K
Replies
6
Views
2K
  • Differential Equations
Replies
4
Views
2K
  • Differential Equations
Replies
13
Views
2K
  • Differential Equations
Replies
8
Views
4K
  • Programming and Computer Science
Replies
4
Views
615
  • Differential Equations
Replies
1
Views
2K
Back
Top