error in ode45 - function must return a column vector
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm trying to get matlab to solve at plot solution lines on top of my slope field. But it just keeps telling me that my function doesn't return a column vector.
I have tried doing the transpose f = f(:); but still doesn't work
this is my code.
f = @(t,y) (3880 - 0.817*y + (731000*y.^7.88)/(116000.^7.88 + y.^7.88));
dirfield(f,0:10:100,0:1000:10000);
hold on;
y0 = 0:100:8000;
f = f(:);
[ts,ys] = ode45(f,[0,50],y0);
plot(ts,ys);
hold off
댓글 수: 0
답변 (1개)
Star Strider
2024년 6월 8일
It would help to have ‘dirfield’ (whatever it is). The other problem is that with one differential equation, ‘y0’ has to have one value, not a vector.
Put the plot and the differential equation solution in a loop, and loop over the ‘y0’ values —
f = @(t,y) (3880 - 0.817*y + (731000*y.^7.88)/(116000.^7.88 + y.^7.88));
% dirfield(f,0:10:100,0:1000:10000);
y0 = 0:100:8000;
figure
hold on
for k = 1:numel(y0)
[ts,ys] = ode45(f,[0,50],y0(k));
plot(ts,ys)
end
hold off
grid
xlabel('tx')
ylabel('ys')
I am not certain what you want as a result.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
