Snippets Collections
# where x is a vector with its first entry x(1) corresponding to the position of a given mass and its second entry x(2) correpsonding to the velocity
dxdt = @(t,x) [x(2); -x(2)-x(1)];
tLim = [0,10];
x0 = [0,1];

[tSol,xSol] = ode45(dxdt, tLim, x0);

plot(tSol, xSol(:,1));
hold on
plot(tSol, xSol(:,2));
# where derivFunction is a fHandle representing the derivative of the dependent variable wrt. the independent variable
# [tSol, ySol] = ode45(derivFunction,interval,initialValue)

# Example:
r = 1;
K = 1000;
# the variables must be passed as independent variable first followed by the dependent variable
odefun = @(t,P) r*P*(1-P/K);
# solution interval values for t
tSpan = [0,10];
P0 = 20;
[tSol, PSol] = oder45(odefun,tSpan,P0)

# plot results
plot(tSol, PSol);
# declare symbolic variables
syms a b c x
y = a*x^2 + b*x + c

soln = solve(y == 0, x);
# solve for specific values
ysoln = subs(soln, [a,b,c],[3,2,-6])
ysoln = simplify(ysoln);

# get decimal number with 9 digits
vpa(ysoln, 9)
xx = -1:0.1:1
y = x.^2
plot(x,y)
xlabel('time [s]')
ylabel('amplitude')
title('my plot')
legend('y(t)')
# multiple line plots
plot(monthz, avgTempLondon,'r:o')
hold on # tells the graph to keep the prior plots
plot(month, avgTempRio, 'b-*')

# mixed plot types
bar(month, maxTempLondon,'yellow')
hold on
plot(monthz, avgTempLondon,'red')
star

Sat Mar 20 2021 07:39:08 GMT+0000 (Coordinated Universal Time)

#matlab
star

Sat Mar 20 2021 07:33:24 GMT+0000 (Coordinated Universal Time)

#matlab
star

Sat Mar 20 2021 07:27:54 GMT+0000 (Coordinated Universal Time)

#matlab
star

Sat Mar 20 2021 07:23:04 GMT+0000 (Coordinated Universal Time)

#matlab #plots
star

Sat Mar 20 2021 07:20:12 GMT+0000 (Coordinated Universal Time)

#matlab #plots

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension