Matlab程序:错误在哪里建立函数文件fun5.mfunction dy=fun5(t,y)dy=[(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*cos(t)-y(1))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2),(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*sin(t)-
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/11 07:49:01
![Matlab程序:错误在哪里建立函数文件fun5.mfunction dy=fun5(t,y)dy=[(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*cos(t)-y(1))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2),(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*sin(t)-](/uploads/image/z/1340373-21-3.jpg?t=Matlab%E7%A8%8B%E5%BA%8F%EF%BC%9A%E9%94%99%E8%AF%AF%E5%9C%A8%E5%93%AA%E9%87%8C%E5%BB%BA%E7%AB%8B%E5%87%BD%E6%95%B0%E6%96%87%E4%BB%B6fun5.mfunction+dy%3Dfun5%28t%2Cy%29dy%3D%5B%28-5%2Asin%28t%29%2A%285%2Acos%28t%29-y%281%29%29%2B5%2Acos%28t%29%2A%285%2Asin%28t%29-y%282%29%29%29%2A%285%2Acos%28t%29-y%281%29%29.%2F%28%285%2Acos%28t%29-y%281%29%29%5E2%2B%285%2Asin%28t%29-y%282%29%29%5E2%29%2C%28-5%2Asin%28t%29%2A%285%2Acos%28t%29-y%281%29%29%2B5%2Acos%28t%29%2A%285%2Asin%28t%29-y%282%29%29%29%2A%285%2Asin%28t%29-)
Matlab程序:错误在哪里建立函数文件fun5.mfunction dy=fun5(t,y)dy=[(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*cos(t)-y(1))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2),(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*sin(t)-
Matlab程序:错误在哪里
建立函数文件fun5.m
function dy=fun5(t,y)
dy=[(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*cos(t)-y(1))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2),
(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*sin(t)-y(2))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2)]
主程序:
clear,clc
close all
[t,y]=ode45('fun5',[0,100],[10,0]);
X=5*cos(t);
Y=5*sin(t);
figure(1)
plot(X,Y,'r.')
hold on
plot(y(:,1),y(:,2),'*')
Matlab程序:错误在哪里建立函数文件fun5.mfunction dy=fun5(t,y)dy=[(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*cos(t)-y(1))./((5*cos(t)-y(1))^2+(5*sin(t)-y(2))^2),(-5*sin(t)*(5*cos(t)-y(1))+5*cos(t)*(5*sin(t)-y(2)))*(5*sin(t)-
标量乘向量还是用点乘吧.
把所有*改成 .*试试行不?
function dy=fun5(t,y)
dy=[(-5.*sin(t)*(5.*cos(t)-y(1))+5.*cos(t)*(5.*sin(t)-y(2)))*(5.*cos(t)-y(1))./((5.*cos(t)-y(1))^2+(5.*sin(t)-y(2))^2),
(-5.*sin(t)*(5.*cos(t)-y(1))+5.*cos(t)*(5.*sin(t)-y(2)))*(5.*sin(t)-y(2))./((5*cos(t)-y(1))^2+(5.*sin(t)-y(2))^2)];
clear,clc
close all
[t,y]=ode45('fun5',[0,100],[10,0]);
X=5.*cos(t);
Y=5.*sin(t);
figure(1)
plot(X,Y,'r.')
hold on
plot(y(:,1),y(:,2),'*')