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

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 Comment

What does the differential equation describe in the real world, and what exactly is the shear rate?

Sign in to comment.

 Accepted Answer

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 Comments

using the for loop I encounter the error:
Error using loglog
Vectors must be the same length.
the size of tau and gamma are as follows:
tau = 1169x1 double
gamma = 1x100 double
Also I dont understand what you meant by the line " % Do something with the t and tau created using this element of gamma "
thanks.
I'm sorry for the inconvenience but I'm very unfamiliar with coding
clc, clearvars, close all
eta0 = 8080;
lambda = 1.109;
gamma = logspace(-3, 3, 100);
for k = 1:numel(gamma)
f = @(t,tau)(-(tau+eta0*gamma(k))/lambda);
[t, tau] = ode45(f, [0.001, 1000], 0);
end
loglog(gamma,tau,'.')
You already asked the same question here:
Did you make progress in understanding how gammadot comes into play ?
Do you have values for gammadot(t) ?
I talked to my professor regarding the same ,
he asked to use a range of values for gammadot preferably using logspace
while gamma dot is shear rate , ive been asked to ignore it for now.
And where is your range of values for gammadot in the time range [0.001 1000] in your code so that we can use it in the ODE ?
There is still the variable gamma instead of gammadot in the function definition. Is this an error ?
I'm sorry I dont understand the first question, Should i define another range for gamma within the loop ?
and secondly i've replace gammadot with gamma to avoid confusion, no other reason
I'm sorry I dont understand the first question, Should i define another range for gamma within the loop ?
In order to solve the ODE, you must have values for gamma(dot) as a function of time. The time range for which you have the values for gamma(dot) should include the time span you use to integrate tau - in your code [0.001 1000].
Or do you want to treat gamma(dot) as a vector of constants and solve for tau for all values of gamma(dot) separately (so that in the end you get the same number of solutions for tau as there are values for gamma(dot) )?
I want to treat gamma dot as a vector of constants
This doesn't answer my question. In both cases, gamma(dot) is a vector of constants.
Again:
Do you want to compute one function for tau and treat gamma(dot) is a function of t
or
do you want to compute as many functions tau as there are parameters for gamma(dot) and treat gamma(dot) as constant for each of these computations ?
I want to treat gamma(dot) as a vector of constants and solve for tau for all values of gamma(dot) separately
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:

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2023b

Tags

Asked:

on 16 Nov 2023

Commented:

on 23 Nov 2023

Community Treasure Hunt

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

Start Hunting!