Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Too many output arguments.Why i am getting this issue

1 visualizzazione (ultimi 30 giorni)
Sohaib naeem
Sohaib naeem il 4 Dic 2016
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commento
Image Analyst
Image Analyst il 4 Dic 2016
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.

Risposte (2)

Tamir Suliman
Tamir Suliman il 5 Dic 2016
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 il 5 Dic 2016
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.

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by