MATLAB: Plot differential equation need help

boundary conditionscodehomeworkodeplot differential equation

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

Best Answer

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
Related Question