Error in Matlab ode45
Show older comments
function dxdt = amanda1(t,x)
dxdt = zeros(2,1);
dxdt(1) = (1/40)*(3.01 - x(1)) - 10000 * exp(-4000/x(2) )* x(1)
dxdt(2) = (1/40)*(257 - x(2)) - (-50/0.99) * (10000 * exp(-4000/x(2)) * x(1));
function [T, X] = amanda2(t,x)
tspan = [0:50:300];
initial = [0.5 250];
[T, X] = ode45(@amanda1,tspan,initial);
fig(1), plot(T,X(:,1), 'o'), title('[CO2] against time'), ylabel('[CO2]'), xlabel('[Time]')
hold on
fig(2), plot(t, x(:,2), '*'), title('T against time'), ylabel('[T]'), xlabel('[Time]')
Uberzyme_System amanda2
i'm trying to plot co2 against time and t versus time using ODE45 differential equations, however this error message kept showing up.
Error in CW1Q3 (line 3) dxdt(1) = (1/40)*(3.01 - x(1)) - (10000 * exp(-4000/x(2)) * x(1))
>> CW1Q3 Not enough input arguments.
Error in CW1Q3 (line 3) dxdt(1) = (1/40)*(3.01-x(1))-10000 * exp(-4000/x(2)) * x(1)
Answers (1)
Star Strider
on 5 Jan 2018
I suspect the errors in your code were obvious to Torsten.
The problem is your ‘amanda2’ function. Functions have their own workspaces, and (except in some specific instances), do not share them with other functions, or with your MATLAB workspace. So the information in ‘amanda2’ is not available to ode45.
With these small changes, your code works for me:
function dxdt = amanda1(t,x)
dxdt = zeros(2,1);
dxdt(1) = (1/40)*(3.01 - x(1)) - 10000 * exp(-4000/x(2) )* x(1);
dxdt(2) = (1/40)*(257 - x(2)) - (-50/0.99) * (10000 * exp(-4000/x(2)) * x(1));
end
tspan = [0:50:300];
initial = [0.5 250];
[T, X] = ode45(@amanda1,tspan,initial);
figure(1), plot(T,X(:,1), 'o'), title('[CO2] against time'), ylabel('[CO2]'), xlabel('[Time]')
figure(2), plot(T, X(:,2), '*'), title('T against time'), ylabel('[T]'), xlabel('[Time]')
Note that if you have all your code in a function (not in a script file), you can run it as I posted it. If you are running it in a script file (rather than in a function file), you have to save ‘amanda1’ to a file named ‘amanda1.m’ on your MATLAB user path. Your code will then work.
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!