Info

此问题已关闭。 请重新打开它进行编辑或回答。

Too many output arguments.Why i am getting this issue

1 次查看(过去 30 天)
function [T,Y] = taylor(f,a,b,ya,m)
syms t y
dfs(1) = symfun(f, [t y]);
for k=1:3
dfs(k+1) = diff(dfs(k),t)+f*diff(dfs(k),y);
end
df = matlabFunction(symfun(dfs,[t y]));
h = (b - a)/m;
T = zeros(1,m+1);
Y = zeros(1,m+1);
T(1) = a;
Y(1) = ya;
for j=1:m
tj = T(j);
yj = Y(j);
D = df(tj,yj);
Y(j+1) = yj + h*(D(1)+h*(D(2)/2+h*(D(3)/6+h*D(4)/24)));
T(j+1) = a + h*j;
end
end
and i m solving f=y-t^2+1
  1 个评论
Image Analyst
Image Analyst 2016-12-4
Why didn't you include the error message? You included only a small, virtually useless part of it. Please include ALL THE RED TEXT, after you read this if course. Also show the code you use to call your taylor() function.

回答(2 个)

Tamir Suliman
Tamir Suliman 2016-12-5
I m not sure exactly but check this code I think you might some thing you initalize to sum the variables then store it again to add it next time
function [T,Y] = taylor(f,a,b,ya,m)
syms t y
dfs(1) = symfun(f, [t y]);
for k=1:3
dfs(k+1) = diff(dfs(k),t)+f*diff(dfs(k),y)
end
df = matlabFunction(symfun(dfs,[t y]));
h = (b - a)/m;
T = zeros(1,m+1);
Y = zeros(1,m+1);
T(1) = a;
Y(1) = ya;
tj=0;yj=0;
for j=1:m
D = df(tj,yj);
Y(j+1) = yj + h*(D(1)+h*(D(2)/2+h*(D(3)/6+h*D(4)/24)));
T(j+1) = a + h*j;
tj = T(j);
yj = Y(j);
end
Tj=tj
Yj=yj

Image Analyst
Image Analyst 2016-12-5
My guess is you called it expecting 3 output arguments, like this:
[T, Y, thirdArg] = taylor(f,a,b,ya,m);
but your code only returns T and Y, not thirdArg.

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by