How do I solve an ode and plot a graph of two terms within the ode
조회 수: 1 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541792/image.png)
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
Sam Chak
2023년 11월 17일
Hi @Namit Dayal
What does the differential equation describe in the real world, and what exactly is the shear rate?
채택된 답변
Steven Lord
2023년 11월 16일
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);
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
Torsten
2023년 11월 23일
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:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!