myfun函数定义成功了,对其变量的输入都是向量,然后对myfun函数求和,组成一个新的函数sourcefile='d:\我的文档\桌面\新建 文本文档.txt' points=textread(sourcefile)a=points(1:25,1)b=points(1:25,2)Z=points(1:25,4)K=s

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 22:51:18
myfun函数定义成功了,对其变量的输入都是向量,然后对myfun函数求和,组成一个新的函数sourcefile='d:\我的文档\桌面\新建 文本文档.txt' points=textread(sourcefile)a=points(1:25,1)b=points(1:25,2)Z=points(1:25,4)K=s

myfun函数定义成功了,对其变量的输入都是向量,然后对myfun函数求和,组成一个新的函数sourcefile='d:\我的文档\桌面\新建 文本文档.txt' points=textread(sourcefile)a=points(1:25,1)b=points(1:25,2)Z=points(1:25,4)K=s
myfun函数定义成功了,对其变量的输入都是向量,然后对myfun函数求和,组成一个新的函数
sourcefile='d:\我的文档\桌面\新建 文本文档.txt' points=textread(sourcefile)
a=points(1:25,1)
b=points(1:25,2)
Z=points(1:25,4)
K=size(a)
m0=10 m1=10 n=100
y=0
for i=1:K
myfun(a(i),b(i),Z(i),m0,m1,n)
y=y+myfunz()
end
myfun函数定义成功了,a,b,Z都是向量,我想对myfun求和,组成一个新的函数

myfun函数定义成功了,对其变量的输入都是向量,然后对myfun函数求和,组成一个新的函数sourcefile='d:\我的文档\桌面\新建 文本文档.txt' points=textread(sourcefile)a=points(1:25,1)b=points(1:25,2)Z=points(1:25,4)K=s
提醒一下:matlab低版本可能不支持中文路径.


这还是单个元素的思路.修改for循环:
a=points(1:25,1)
b=points(1:25,2)
Z=points(1:25,4)
K=size(a)
m0=10 m1=10 n=100
y=0
for i=1:K    
   y=y+myfunz(a(i),b(i),Z(i),m0,m1,n)
end
 

其实matlab中运算都是矩阵形式的,所以可以直接不用for循环的:
修改myfun那个函数中的赋值语句为:
f = (m1*(log10(n*a)./log10(n*b))-m0-Z)).^2;

然后就可以直接中了
a=points(1:25,1)
b=points(1:25,2)
Z=points(1:25,4)
K=size(a)
m0=10 m1=10 n=100
y=sum(myfunz(a,b,Z,m0,m1,n));