Borrar filtros
Borrar filtros

How do I solve an ode and plot a graph of two terms within the ode

1 visualización (últimos 30 días)
I have to plot gamma dot vs tau
where gamma dot can be defined in the range logspace(-3,3,100)
my attempt at this is as follows:
clc, clearvars, close all
eta0 = 8080;
lambda = 1.109;
gamma = logspace(-3, 3, 100);
f = @(t,tau)(-(tau+eta0*gamma)/lambda);
[t, tau] = ode45(@f,[0.001 1000], 0);
loglog(gammaint,tau,'.')
and ive recieved the error messages as follows:
Undefined function 'f' for input arguments of type 'double'.
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode,
tspan, y0, options, varargin);
Error in maxwell5 (line 9)
[t, tau] = ode45(@f,[0.001 1000], 0);
What can i do to fix this,
Thanks
  1 comentario
Sam Chak
Sam Chak el 17 de Nov. de 2023
What does the differential equation describe in the real world, and what exactly is the shear rate?

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 16 de Nov. de 2023
eta0 = 8080;
lambda = 1.109;
gamma = logspace(-3, 3, 100);
f = @(t,tau)(-(tau+eta0*gamma)/lambda);
f is already a function handle. So there's no need to specify @f on the next line. Just pass f into ode45. But if you do that you run into a different problem:
[t, tau] = ode45(f,[0.001 1000], 0);
Error using odearguments
@(T,TAU)(-(TAU+ETA0*GAMMA)/LAMBDA) must return a column vector.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
loglog(gammaint,tau,'.')
MATLAB calls the ODE function that you pass into ode45 with a vector of values for the second input. If you're trying to solve this for each value of gamma in turn, use a for loop over the elements of gamma. Define f using each element from gamma in turn then call ode45 using that function.
for k = 1:numel(gamma)
f = @(t,tau)(-(tau+eta0*gamma(k))/lambda);
[t, tau] = ode45(f, [0.001, 1000], 0);
% Do something with the t and tau created using this element of gamma
end
If instead you want gamma to be treated as a function of time whose value you only know at specific times, you're going to have to interpolate the value of gamma for the value of t with which ode45 calls the function. See the "ODE with Time-Dependent Terms" example on the ode45 documentation page for an example of this technique.
Finally, I don't know if it's just that you didn't show the definition of the variable or made a typo in the line, but your call to loglog throws an error because gammaint isn't defined.
  10 comentarios
Namit Dayal
Namit Dayal el 23 de Nov. de 2023
I want to treat gamma(dot) as a vector of constants and solve for tau for all values of gamma(dot) separately
Torsten
Torsten el 23 de Nov. de 2023
That's simple because an analytical solution for tau exists in which you only need to insert the values for the parameters you want to use:

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by