用matlab ode45解二次导数并根据解的系数变化画出所有图像X''+2*zeta*X'+X=cos(t)zeta是一个有多个元素的向量已经写出了求原式子的部分:unction out = hw2Q4() clear allclose allclctspan = [0 40]; %Range of t we are
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/13 05:26:20
用matlab ode45解二次导数并根据解的系数变化画出所有图像X''+2*zeta*X'+X=cos(t)zeta是一个有多个元素的向量已经写出了求原式子的部分:unction out = hw2Q4() clear allclose allclctspan = [0 40]; %Range of t we are
用matlab ode45解二次导数并根据解的系数变化画出所有图像
X''+2*zeta*X'+X=cos(t)
zeta是一个有多个元素的向量
已经写出了求原式子的部分:
unction out = hw2Q4()
clear all
close all
clc
tspan = [0 40]; %Range of t we are solving
initcond = [0 0]; %Initial condition
sol = ode45(@odeFun,tspan,initcond); %Solves the ode
tao = 0:0.01:40; %Create a vector with evenly spaced times
X = deval(sol,tao,1); %Evaluate solution vector y at times in t
z = deval(sol,tao,2);
plot(tao,X,'-b');
xlabel('tao');
ylabel('X');
title('X''''+2*zetaX''+X=cos(tao),y(0)=0,y''(0)=0');
end
function dX = odeFun(tao,X) %This function contains the ode
dX(1) = X(2);
dX(2) = -2*zeta(i)*X(2)-X(1)+cos(tao);
dX=dX';
end
想用zeta = [0.2:0.2:1.4]
for i=1:length(zeta)
end
来把zeta的所有元素代入式子后的图像都画在一个图像上.求问要怎么画呢?>_
用matlab ode45解二次导数并根据解的系数变化画出所有图像X''+2*zeta*X'+X=cos(t)zeta是一个有多个元素的向量已经写出了求原式子的部分:unction out = hw2Q4() clear allclose allclctspan = [0 40]; %Range of t we are
参考代码:
function out = hw2Q4()
tspan = [0 40]; %Range of t we are solving
initcond = [0 0]; %Initial condition
Zeta = [0.2:0.2:1.4];
clf
for zeta=Zeta
sol = ode45(@odeFun,tspan,initcond,[],zeta); %Solves the ode
tao = 0:0.01:40; %Create a vector with evenly spaced times
X = deval(sol,tao,1); %Evaluate solution vector y at times in t
z = deval(sol,tao,2);
plot(tao,X,'-b');
hold on
end
xlabel('tao');
ylabel('X');
title('X''''+2*zetaX''+X=cos(tao), y(0)=0, y''(0)=0');
function dX = odeFun(tao,X,zeta) %This function contains the ode
dX(1) = X(2);
dX(2) = -2*zeta*X(2)-X(1)+cos(tao);
dX=dX';
function out = hw2Q4()
clear all
close all
clc
tspan =linspace(0,40)'; %Range of t we are solving
initcond = [0 0]; %Initial condition
figure;hold on
for zeta =[0.2:0.2...
全部展开
function out = hw2Q4()
clear all
close all
clc
tspan =linspace(0,40)'; %Range of t we are solving
initcond = [0 0]; %Initial condition
figure;hold on
for zeta =[0.2:0.2:1.4]
[t,y]=ode45(@(tspan,X,zeta) odeFun(tspan,X,zeta),tspan,initcond,[],zeta); %#ok
x=y(:,1);
plot(t,x,'-b');
end
xlabel('tao');
ylabel('X');
title('X''''+2*zetaX''+X=cos(tao), y(0)=0, y''(0)=0');
end
function dX =odeFun(tspan,X,zeta) %This function contains the ode
dX=[0,0]';
dX(1) = X(2);
dX(2) = -2*zeta*X(2)-X(1)+cos(tspan);
end
收起