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