# Solving One Equation on Matlab: Finding Parameter p

• MATLAB
• FrancescoMi
In summary, the conversation discusses solving an equation on Matlab to find the value of p, where psi is a function and psi' is its derivative. The code provided involves calculating derivatives and using the solve function to find the free boundary, but there may be issues with the code and results. The suggestion is made to separate the mathematics from the code and seek help in the Calculus forums before reposting with updated code.
FrancescoMi
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:

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
> In solve at 306

FreeBoundary =

1.0

Any updates or other information you can provide?

Delong

## 1. How do I enter an equation in Matlab?

To enter an equation in Matlab, you can use the symbol 'syms' to define symbolic variables and then use the 'solve' function to solve the equation for a specific variable. For example, if your equation is 2x + 4 = 10, you would enter the following code:
syms x
solve(2*x + 4 == 10, x)
This will give you the value of x, which in this case is 3.

## 2. Can I solve equations with multiple variables in Matlab?

Yes, Matlab can solve equations with multiple variables. You can use the same 'syms' and 'solve' functions, but you will need to specify which variable you want to solve for in the 'solve' function. For example, if your equation is 3x + 5y = 20 and you want to solve for x, you would enter the following code:
syms x y
solve(3*x + 5*y == 20, x)
This will give you the value of x in terms of y.

## 3. How can I find the value of a specific parameter in an equation on Matlab?

To find the value of a specific parameter, you can use the 'subs' function in Matlab. This function allows you to substitute a value for a variable in an equation. For example, if your equation is x^2 + y = p and you want to find the value of p when x = 3, you would enter the following code:
syms x y p
eqn = x^2 + y == p
subs(eqn, x, 3)
This will give you the value of p, which in this case is 9 + y.

## 4. Is there a way to graph the solution to an equation in Matlab?

Yes, you can use the 'ezplot' function in Matlab to graph the solution to an equation. This function takes in an equation and automatically generates a graph of the solution. For example, if your equation is x^2 + 4x - 3 = 0, you would enter the following code:
syms x
ezplot(x^2 + 4*x - 3)
This will generate a graph of the solution to the equation, which in this case is a parabola.

## 5. How do I save the solution to an equation in Matlab?

To save the solution to an equation in Matlab, you can use the 'save' function. This function allows you to save a variable or set of variables to a file for later use. For example, if you want to save the solution to the equation x^2 + 4x - 3 = 0, you would enter the following code:
syms x
solution = solve(x^2 + 4*x - 3 == 0, x)
save('solution.mat', 'solution')
This will save the solution to a file named 'solution.mat' that you can then load and use in future Matlab sessions.

• MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
877
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
6K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• Special and General Relativity
Replies
1
Views
954
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K