MATLAB Solving One Equation on Matlab: Finding Parameter p

  • Thread starter Thread starter FrancescoMi
  • Start date Start date
  • Tags Tags
    Matlab Parameter
AI Thread Summary
The discussion focuses on solving the equation (p-c)*psi'-psi=0 in Matlab to find the parameter p, where psi is defined by a complex function involving integrals and derivatives. The user has shared their code, which calculates derivatives and attempts to solve for p but only works under the condition that rho > eta and produces strange results for varying sigma values. Responses indicate that the request for manual verification of the entire code is unreasonable, suggesting a separation of mathematical issues from coding problems. Additionally, the code fails to run correctly, returning a numeric approximation instead of a symbolic solution. Further refinement of both the mathematical expressions and the code is recommended for better results.
FrancescoMi
Messages
5
Reaction score
0
Hi, I have to solve one equation on Matlab. The equation is: (p-c)*psi'-psi=0 I have to find p. Where psi is:

2pyp9u0.png


and psi' is the derivative of psi. I've written this code:
Matlab:
rho = 0.04; %In the image is lambda
c = 25;
eta = 0.02;
mu = 40;
sigma  = 0.57;
alpha = -rho/eta;

syms p t
F = t^(-alpha-1)*exp(-t^2/2+((p-mu)/sigma*sqrt(2*eta))*t); %Funzione integranda non derivata
F_d = t^(-alpha-1)*(t*sqrt(2*eta))/sigma*exp(-t^2/2+((p-mu)/sigma*sqrt(2*eta))*t); %Funzione integranda derivata
D = (exp(((p-mu)/sigma*sqrt(2*eta))^2/4)/gamma(-alpha))*int(F,t,0,inf); %Funzione cilindrica non derivata
D_d = (exp((((p-mu)/sigma*sqrt(2*eta))^2)/4)/gamma(-alpha))*int(F_d,t,0,inf)+((eta*(p-mu))/(4*(sigma)^2))*(exp((((p-mu)/sigma*sqrt(2*eta))^2)/4)/gamma(-alpha))*int(F,t,0,inf); %Funzione cilindrica derivata
psi = exp((eta*(p-mu)^2)/(2*(sigma)^2))*D;
psi_d = (eta*(p-mu))/(sigma^2)*exp((eta*(p-mu)^2)/(2*(sigma)^2))*D + exp((eta*(p-mu)^2)/(2*(sigma)^2))*D_d; %Derivata di psi
Theta = (p-c)*psi_d-psi;

FreeBoundary = solve(Theta,p)

I've calculated the derivatives by myself, and I hope they are ok. What do you think about the code? It works only if rho>eta. Moreover for different values of sigma it give me some strange results.
Do you think the code is right and the derivatives are correct?
 
I think the problem with this post is the question posed:

"Do you think the code is right and the derivatives are correct?"

It is unreasonable to request that someone manually check all of your work and then debug your code on this scale. This could easily take a few hours, which is why nobody has responded.

Let's separate the math from the code: if you have a problem with the derivative or equations, post that in the Calculus forums. Once you nail down the expression you want to solve, I suggest you repost here with some updated code. The code you posted didn't run for me, so there is at least a little more work to be done:

Code:
Warning: Cannot solve symbolically. Returning a numeric
approximation instead. 
> In solve at 306 

FreeBoundary =

1.0

Any updates or other information you can provide?
 
  • Like
Likes Delong

Similar threads

Replies
10
Views
3K
Replies
4
Views
1K
Replies
2
Views
3K
Replies
5
Views
2K
Replies
3
Views
3K
Replies
4
Views
1K
Replies
6
Views
7K
Back
Top