Not enough input arguments for my ode15s solver
3 次查看(过去 30 天)
显示 更早的评论
I got my code following
clear
load("BurgersMatrices_2022.mat");
T = 3; nt = 600; tspan = linspace(0,T,nt);
options = odeset('Mass',E);
x0 = [0; x0b ; 0];
[tout,xout] = ode15s(prime,tspan,x0,options);
function out = prime(x)
load("BurgersMatrices_2022.mat");
J = nonzeros(A); A1 =J(1) ; A2 = J(2);
J = nonzeros(H); H2 = J(2); H3 = J(1);
for j = 2:1025
one(j) = A1*x(j) + A2*(x(j-1)+x(j+1));
two(j) = H2*(x(j+1))^2 + H3*(x(j-1))^2;
out(j) = one(j)-0.5*two(j);
end
out(1026) = 0;
out = out';
end
where my x0b is a 1024*1 vector and x0 vector is 1026*1. E is a mass matrix for E (dx/dt) = f(x). I got the error "Not enough input arguments." saying
Error in HW1_P1>prime (line 21)
one(j) = A1*x(j) + A2*(x(j-1)+x(j+1));
Error in HW1_P1 (line 14)
[tout,xout] = ode15s(prime,tspan,x0,options);
i'm not sure what's wrong with it, could anyone help me with this? Thank you.
0 个评论
采纳的回答
Steven Lord
2022-10-19
Your code attempts to call your prime function with 1 output and 0 inputs and use whatever it returns as the first input to ode15i. But as written your prime function requires 1 input. You need to pass a function handle to your prime function into ode15i.
ode15i(@prime, ...
However, this still won't work but for a different reason. As stated on the ode15i documentation page, the function handle input to the solver "must accept the three inputs for t, y, and yp even if one of the inputs is not used in the function." Your prime function only accepts 1 input, which plays the role of t (using the terminology from the documentation page.) It needs to accept y and yp as well.
I also strongly recommend you not call load in your prime function. That will cause MATLAB to load the MAT-file each and every time ode15i calls your function, which likely will take a lot of time. Instead load the MAT-file once before calling ode15i and pass whatever additional parameters prime needs into it using the techniques from this documentation page that is also linked from the documentation for the odefun input argument on the ode15i documentation page.
4 个评论
Steven Lord
2022-10-20
That looks like it can be written in the form ode45 or ode15s expects. In this case, using the formulation given on those documentation pages () your mass matrix is E and the function you write to serve as f(t, x) needs to evaluate . If you're not sure how to handle the mass matrix, the "Summary of ODE Examples and Files" section on this documentation page lists a few examples that each involve a mass matrix that you could use as guidance.
Can you show the code you've written to try to solve this system using ode45 and explain what "none of them works" means in this context?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
This is getting a little bit away from the topic of the original question you asked, so you might want to post that as a new question with a link back to this one for reference.
更多回答(1 个)
Torsten
2022-10-19
options = odeset('Mass',E);
E is not defined.
x0 = [0; x0b ; 0];
x0b is not defined.
[tout,xout] = ode15s(prime,tspan,x0,options);
Must read
[tout,xout] = ode15s(@(t,y)prime(y),tspan,x0,options);
load("BurgersMatrices_2022.mat");
We don't know the content of "BurgersMatrices_2022.mat"
for j = 2:1025
one(j) = A1*x(j) + A2*(x(j-1)+x(j+1));
two(j) = H2*(x(j+1))^2 + H3*(x(j-1))^2;
out(j) = one(j)-0.5*two(j);
end
out(1) is not defined.
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!