Hi all, What I'm trying to do is plot 5 curves on 1 figure. The difference between the curves is by varying the constant "A".
Please let me where and what I've done wrong. I've 2 codes, the first is a function which calls the other function and the second is the "integrating" function.
Thank you.
"Main" function:
function Plotting_Of_Different_A_Values
tstart = 0;
tend = 10;
n = 10000;
tspan = linspace(tstart,tend,n);
xinit = [0;0];
beta = 55;
gamma = 0.2;
%g = 9.8;
A = [0.5,1,1.5,2,5];
options = odeset('RelTol', 1e10, 'AbsTol', 1e10);
for k = 1:length(A)
%[t,x] = ode45(@(t,x)IntegratingFunction(t,x,beta,gamma,A(k)), tspan, xinit,options);
[tLinear,y] = ode45(@(tLinear,y)IntegratingFunction2(tLinear,y,beta,gamma,A(k)), tspan, xinit,options);
%z = x(:,1);
zLinear = y(:,1);
%driLinear = (beta^2/g)* max(zLinear);
if A(k) == 0.5
figure(1);
plot(tLinear,zLinear,'r');
text(2,0.0447, 'A=0.5');
text(2,0.21, 'A=0.5');
elseif A(k) == 1
plot(tLinear,zLinear,'g');
text(2,0.07, 'A=1');
text(2,0.345, 'A=1');
elseif A(k) == 1.5
plot(tLinear,zLinear,'b');
text(1.5,0.07, 'A=1.5')
text(2,0.4, 'A=1.5')
elseif A(k) == 2
plot(tLinear,zLinear,'m');
text(2.75,0.075, 'A=2')
text(2,0.425, 'A=2')
else
plot(tLinear,zLinear,'k');
text(2.65,0.4125, 'A=5')
text(1.15,0.075, 'A=5')
end
hold on
xlabel('t(s)');
ylabel('Z');
end
end
SECOND FUNCTION:
function [ dydt ] = IntegratingFunction2(tLinear,y,beta,gamma,A)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
z = y(1);
zdot = y(2);
dydt = zeros(size(y));
dydt(1) = zdot;
dydt(2) = heaviside(A*tLinear) + 4*heaviside(A*(tLinear1))  5*heaviside(A*(tLinear3))  beta*gamma*zdot  beta*z;
return
