作业帮 > 综合 > 作业

MATLAB function的问题- -

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/09 06:27:00
MATLAB function的问题- -
初学MATLAB一道简单的习题.卡住了 - -
求助:
题目大意是这样:一个在X-Y面板上移动的物体随着时间t的变化变换位置,坐标(x,y)
x = 2 cos t (1-cos t),
y = 2 sin t (1-cos t).
求写个MATLAB function,让用户输入t,便可计算出物体在时间t时的坐标.
想了好久好久.就一直是
? Input argument "k" is undefined.
Error in ==> varTime at 6
for n = 1:k
有高手可以帮忙下吗0.0
function [x,y] = varTime(t)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
for t=1:t
x(t) = 2 .*cos((t).*(1-cos(t)));
y(t) = 2 .*sin((t).*(1-cos(t)));
end
x
y
end
我写成这样.
然后一直出错0.0 3楼的不会出错但是,会直接给出图,无法input t.
? Input argument "t" is undefined.
Error in ==> varTime at 4
for t=1:t
function [x,y]=location(t)
x=2*cos(t)*(1-cos(t));
y=2*sin(t)*(1-cos(t));
函数是这样写的,如果要计算x,y的值时,现需要把函数保存一下,然后在matlab命令窗口command window中用[x,y]=location(t)就行,这时,括号里的t可以进行赋值了,如[x,y]=location(3)等.而且在current directory里要出现保存的这个文件(如果没出现这个保存的文件,那么执行程序会出错的)
你按照上面的做了以后,这个[x,y]=location(t)中,t可以任意给值啊,没必要input(t)啊
要不,你在hi中留言吧,我一般会看到的