# plot differential equation need help

3 ビュー (過去 30 日間)
mary m 2019 年 6 月 23 日
コメント済み: Bjorn Gustavsson 2019 年 6 月 24 日
Hi. I want to plot (q,y) for three values of x=1,2,3 with two boundary conditions for this differential equation?
how can I write a code

#### 3 件のコメント

infinity 2019 年 6 月 24 日
Hello,
Did you find the solution of this equation?
Like y = function(x,q).
In your problem, the domain of x from 0 to 2, but you say that you want to plot (q,y) for x = 1, 2, 3. Do you have solution for x = 3?
Aquatris 2019 年 6 月 24 日
Do you want to solve it analytically or numerically?
Bjorn Gustavsson 2019 年 6 月 24 日
Solve it analytically - ought to be simple enough to do by hand. That will give you y(x,q), plot for desired values of q a desired points x.
HTH

サインインしてコメントする。

### 採用された回答

Pullak Barik 2019 年 6 月 24 日
I tried a way out, tell me if it helps-
clc
syms y(x);
syms q;
Dy = diff(y);
ode = diff(y,x,2) + q*y == 10*q; %The equation to solve
cond1 = y(0) == 0; %Initial condition 1
cond2 = Dy(2) == 0; %Initial condition 2
conds = [cond1 cond2];
ySol(x) = dsolve(ode, conds); %Solution in terms of x and q
ySol = simplify(ySol)
syms f1 f2 f3;
f1(q) = ySol(1) %substituting x = 1
f2(q) = ySol(2) %substituting x = 2
f3(q) = ySol(3) %substituting x = 3
%f1, f2, f3 now contain the required functions, plotting them below for brevity
figure;
hold on;
subplot(3,1,1)
title('x=1')
fplot(f1);
subplot(3,1,2)
fplot(f2);
subplot(3,1,3)
fplot(f3);
hold off;
You may refer to the following links for help in understanding the above code-
1) Usage of syms- syms
2) Solving differential equations in MATLAB- Solve Differential Equation
3) Plotting symbolic equations- fplot

#### 4 件のコメント

Bjorn Gustavsson 2019 年 6 月 24 日
Mary, for every value of q you have a linear second order ODE with constant coefficients and two conditions on the solution...
mary m 2019 年 6 月 24 日
I dont have amount of q. I want to plot y-q.
Bjorn Gustavsson 2019 年 6 月 24 日
Yes, I do understand that you want the curve of y(x=2,q) for a range of values of q. Now, for each and every value of q, your ODE as written will be a second order differential equation with constant coefficients. That type of ODE have a very simple analytical solution, where you do not have to plug in the value of q to get the solution for y. This is, I think, something that you are expected to learn properly, my advice is that you still do this by pen and paper just to understand the concept of "characteristic polynomial" as well as the separation of particular and homogenous solutions and how you adjust the coefficients to satisfy the initial/boundary-conditions. But I can only suggest, it is your learning to do.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by