i have given three differential equations for which i need graph using matlab code . is the code right?

1 view (last 30 days)
clc
clear all;
syms XS X1
ode1 = diff(XS) == (XS-XS.*XS)(XS-0.17)(0.36*XS*X1)(θ.0001*XS*Y)/(1+0.2*XS);
ode2 = diff(X1) == (X1)(0.06*XS-4.06*X1*Y-0.09)
ode3 = diff(Y) == (0.000089XS*Y)/(1+0.2*XS)-0.232X1-Y
cond = x(s) > 0;
[XSSol(t),X1Sol(t),YSol(t)] = dsolve(odes,conds)
fplot(XSSol)
hold on
fplot(X1Sol)
hold on
fplot(YSol)
legend('XSSol','X1Sol','YSol')
I have written this code and I want to know if the code is right for the given two equations.

Answers (1)

Riya
Riya on 5 Feb 2024
Hi
Here's a revised version of the code with corrections and proper MATLAB syntax for solving and plotting the solutions to the system of differential equations:
clc;
clear all;
% Define symbolic variables and functions
syms XS(t) X1(t) Y(t)
% Define the differential equations
ode1 = diff(XS, t) == (XS-XS*XS)*(XS-0.17) - (0.36*XS*X1*(theta*0.0001*sqrt(XS)*Y))/(1+0.2*sqrt(XS));
ode2 = diff(X1, t) == (X1)*(0.06*XS - 4.06*X1*Y - 0.09);
ode3 = diff(Y, t) == (0.000089*sqrt(XS)*Y)/(1+0.2*sqrt(XS)) - 0.232*X1 - Y;
% Combine the ODEs into a system
odes = [ode1; ode2; ode3];
% Define initial conditions (example initial conditions, adjust as necessary)
cond1 = XS(0) == 1; % Initial condition for XS
cond2 = X1(0) == 1; % Initial condition for X1
cond3 = Y(0) == 1; % Initial condition for Y
% Solve the system of ODEs
conds = [cond1; cond2; cond3];
[XSSol(t), X1Sol(t), YSol(t)] = dsolve(odes, conds);
% Plot the solutions
fplot(XSSol, 'b', 'LineWidth', 1.5); % Plot XS solution in blue
hold on;
fplot(X1Sol, 'r', 'LineWidth', 1.5); % Plot X1 solution in red
fplot(YSol, 'g', 'LineWidth', 1.5); % Plot Y solution in green
hold off;
% Add legend
legend('XS(t)', 'X1(t)', 'Y(t)');
% Label the axes
xlabel('Time t');
ylabel('Solutions');
% Add a title
title('Solutions to the Differential Equations');
Since it is unclear what the value of theta should be, you'll need to assign it a numeric value before using it in the equations. If theta is not meant to be a variable from any of the toolboxes like Sensor Fusion and Tracking Toolbox, Navigation Toolbox ,Robotics System Toolbox, ROS Toolbox, UAV Toolbox then simply define it as a constant in your workspace.
For more information refer following documentation:

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!