Coding a second degree differential equation

์กฐํšŒ ์ˆ˜: 2 (์ตœ๊ทผ 30์ผ)
Rozhin Parvaresh
Rozhin Parvaresh 2019๋…„ 11์›” 29์ผ
๋Œ“๊ธ€: Dhananjay Kumar 2019๋…„ 12์›” 5์ผ
Hello,
I am trying to code a nonlinear second degree differential equation with 2 boundary conditions.
I have included a screenshot of the equation where ?_r is a function of C. ?_0, z, and F are constants. The system is 1-D.
I am having trouble coding phi, since I don't have a function of "phi=..." and even if I want to use diff(phi,2), I don't know how to code abstractly with variables.
  ๋Œ“๊ธ€ ์ˆ˜: 2
darova
darova 2019๋…„ 11์›” 29์ผ
What are and ? Where are they?
Rojan Parvaresh
Rojan Parvaresh 2019๋…„ 11์›” 29์ผ
ํŽธ์ง‘: Rojan Parvaresh 2019๋…„ 11์›” 29์ผ
C is for concentration . z_i is charge which is constant for each species of i. For example z of OH- is -1.
Regarding C, there is another transient equation that I was able to code. I have attached the equation.
So the previous equation and the transient equation need to be solved simultaneously and i'm having trouble coding the d^2(phi)/dx^2 equation from above
P.S. D_i is the diffusion coefficient which is also a constant for each species i.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (1๊ฐœ)

Dhananjay Kumar
Dhananjay Kumar 2019๋…„ 12์›” 3์ผ
You can declare phi as a symbolic variable by using syms command and sove the equation symbolicaly as we solve any equation by hand.
  ๋Œ“๊ธ€ ์ˆ˜: 2
Rojan Parvaresh
Rojan Parvaresh 2019๋…„ 12์›” 4์ผ
Hi, so I'm still having trouble even with using syms.
I have attached my code and you have the equations, I keep getting an error in my for loop
Dhananjay Kumar
Dhananjay Kumar 2019๋…„ 12์›” 5์ผ
Hey, as I mentioned Symbolic variables are used to sove equations or evaluate expressions symbolically (the way we differentiate/integrate functions on our notebooks).
Suppose you want to get derivative of cos(x), then you do this:
>> syms x;
>> syms y(x); (This statement tells MATLAB that y is a function of x)
>> y = cos(x)
>> yd = diff(y)
This gives you yd = -sin(x).
If you want to evaluate value of the symbolic expression/function, you should use subs function (not like cos(pi), the way you have written in the code).
In your code, you first need to declare x as symbolic variable. Also, to declare a function c dependent on t, t should be symbolic not a constant value.
Please read the documentation and go through the examples to get more abstract view.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Symbolic Math Toolbox์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by