Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Too many output arguments.Why i am getting this issue

조회 수: 1 (최근 30일)
Sohaib naeem
Sohaib naeem 2016년 12월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
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