Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Demo Matlab 2

The document provides a series of MATLAB demonstrations covering factorization, solving equations, plotting functions, and using ODE solvers like ode23. It includes examples of polynomial factorization, root finding, and solving ordinary differential equations with specified initial conditions. The code snippets illustrate how to perform these tasks using symbolic variables and plotting results in MATLAB.

Uploaded by

dipanjanbarman79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Demo Matlab 2

The document provides a series of MATLAB demonstrations covering factorization, solving equations, plotting functions, and using ODE solvers like ode23. It includes examples of polynomial factorization, root finding, and solving ordinary differential equations with specified initial conditions. The code snippets illustrate how to perform these tasks using symbolic variables and plotting results in MATLAB.

Uploaded by

dipanjanbarman79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DEMO MATLAB 2

Saturday, 20 March 2021 10:56 AM

Demo Factorization

F = factor(213)
syms x
eq = x^2 + 6*x + 9
factor(eq,x)%if possible, gives factors

Solequation

x=-1:.01:1;
y= sqrt(1-x.^2);
x1=0:0.01:1;
y1=1-x1;
%xlim([-2 2])
%ylim([-2 3])
plot(x1,y1)
grid on
hold on
plot(x,-y)
hold on
plot(x,y)
line([2 -2],[0 0],'color','b')% line[x1,x2],[y1,y2] to drae line (x1,y1)-(x2,y2)
line([0 0],[2 -2],'color','r')
xlim([-2 2])
ylim([-2 3])

Demopolynomialsymbol
syms x y
eqn = x^3 == 1000+y^3;
S = solve(eqn,x)
S = solve(eqn,y)

% Solve the quadratic equation without specifying a variable to solve


syms a b c x
% given eqn = ax^2+bx+c=0
eqn = a*x^2 + b*x + c == 0
S = solve(eqn)%solve symbolically for x

%Specify the variable to solve for and solve the quadratic equation for a.
eqn = a*x^2 + b*x + c == 0
Sa = solve(eqn,b)% solve for b

% If some var is assigned values


eqn = 4*x^2 - 4*x + 1 == 0
S = solve(eqn)
==============Demoroot======================

%Solve the equation 3x^2 - 2x?4=0.


%Create a vector to represent the polynomial, then find the roots.
p = [3 -2 -4];
r = roots(p)
%Solve the equation x^2 -1=0
p = [1 0 -1];
r = roots(p)
%Solve the equation x^4 -1=0
p = [1 0 0 0 -1];
r = roots(p)
------------------------------------------------
Demoode23

%Solve the ODE, say dy/dt=2t, expt with other fn


%Use a time interval of [0,50] and the initial condition y0 = 0.
tspan = [0 50];
y0 = 0;
% ode23 is the solver - an implementation of an explicit Runge-Kutta method
% note: ode23 is a three-stage, third-order, Runge-Kutta method.
% another ODE solver ode45 is a six-stage, fifth-order, Runge-Kutta method.
% ode45 does more work per step than ode23,
[t,y] = ode23(@(t,y) 2*t, tspan, y0);% RHS is passed in calling function ode23
%Plot the solution.
plot(t,y) % add '-o'to use - in plot, in color o
===
%Solve the ODE, say dy/dt=2t, expt with other fn
%Use a time interval of [0,50] and the initial condition y0 = 0.
tspan = [0 10];
y0 = 2;
% ode23 is the solver - an implementation of an explicit Runge-Kutta method
% note: ode23 is a three-stage, third-order, Runge-Kutta method.
% another ODE solver ode45 is a six-stage, fifth-order, Runge-Kutta method.
% ode45 does more work per step than ode23,
[t,y] = ode23(@(t,y) 2*t, tspan, y0);% RHS is passed in calling function ode23
%Plot the solution.
plot(t,y, '-b') % add '-r'to use - in plot, in color r etc
===============================================
%Solve the ODE, say dy/dt=2t, expt with other fn
%Use a time interval of [0,50] and the initial condition y0 = 0.
tspan = [0 10];
y0 = 2;
% ode23 is the
solver - an implementation of an explicit Runge-Kutta method
% note: ode23 is a three-stage, third-order, Runge-Kutta method.
% another ODE solver ode45 is a six-stage, fifth-order, Runge-Kutta method.
% ode45 does more work per step than ode23,
[t,y] = ode23(@(t,y) 2*t, tspan, y0);% RHS is passed in calling function ode23
%Plot the solution.
plot(t,y, '-b') % add '-r'to use - in plot, in color r etc
===============================================================

You might also like