Swordkill38

10 Reputation

2 Badges

4 years, 333 days

MaplePrimes Activity


These are questions asked by Swordkill38

I am having some issues trying to convert this matlap code into Maple code, can somebody help me out?

% Solve v'(t)=-0.0207v(t)^2-893.58 with y0=0
clc;
y0 = 0;                  % Initial Condition
h = 0.1;                 % Time step
t = 0:h:5;               % t goes from 0 to 5 seconds.
vstar = zeros(size(t)); % Preallocate array (good coding practice)
vstar(1) = y0;           % Initial condition gives solution at t=0.
for i=1:(length(t)-1)
    k1 = 0.0207*vstar(i)^2-893.58; % Previous approx for y gives approx for derivative
    vstar(i+1) = vstar(i) + k1*h; % Approximate solution for next value of y
end
figure(1)
plot(t,vstar);
y0 = 0;                  % Initial Condition
h = 0.05;                 % Time step
t = 0:h:5;               % t goes from 0 to 5 seconds.
vstar = zeros(size(t)); % Preallocate array (good coding practice)
vstar(1) = y0;           % Initial condition gives solution at t=0.
for i=1:(length(t)-1)
    k1 = 0.0207*vstar(i)^2-893.58; % Previous approx for y gives approx for derivative
    vstar(i+1) = vstar(i) + k1*h; % Approximate solution for next value of y
end
figure(2)
plot(t,vstar);

My assignment is to plot 3 graphs when u0=65.70 and 95 and I thought I did my code properly but now I am getting weird errors

 

a0:=80;
a1:=-5;
b1:=-5*(3)^0.5;
w:=Pi/12;
k:=0.2;
u0:=65;

t=0:0.001:100;
c0=u0-a0-(k^2*a1-k*w*b1)/(k^2+w^2);
c1=(k^2*a1-k*w*b1)/(k^2+w^2);
d1=(k*w*a1+k^2*b1)/(k^2+w^2);
u=a0+c0*exp(-k*t)+c1*cos(w*t)+d1*sin(w*t);
plot(t,u,'r');

I am getting an error here that says Error, (in plot) unexpected options: [65., r] and I don't know how to fix this


legend('u(0)=65');


hold on;
u0=70;
c0=u0-a0-(k^2*a1-k*w*b1)/(k^2+w^2);
c1=(k^2*a1-k*w*b1)/(k^2+w^2);
d1=(k*w*a1+k^2*b1)/(k^2+w^2);
u=a0+c0*exp(-k*t)+c1*cos(w*t)+d1*sin(w*t);
plot(t,u,'-');

I am also getting an error with the '-' portion of my plot "Error, invalid uneval"

legend('u(0)=70');


hold on;
u0=95;
c0=u0-a0-(k^2*a1-k*w*b1)/(k^2+w^2);
c1=(k^2*a1-k*w*b1)/(k^2+w^2);
d1=(k*w*a1+k^2*b1)/(k^2+w^2);
u=a0+c0*exp(-k*t)+c1*cos(w*t)+d1*sin(w*t);
plot(t,u,'g');

I am getting an error yet again with my plot and this time it is "Warning, expecting only range variable u in expression t to be plotted but found name t"


legend('u(0)=90');

Page 1 of 1