Need help solving and plotting a first order pde

2 views (last 30 days)
I've tried using ode45 however the values for tau come out to be negative which shouldn't be possible
I need to plot tau vs gamma
The code for the same :
clc, clearvars, close all
eta0 = 8080;
lambda = 1.109;
gamma = logspace(-3, 3, 100);
f = @(t, tau) (-(tau + eta0 * interp1(linspace(0, 100, length(gamma)), gamma, t)) / lambda);
[t, tau] = ode45(f, [0, 100], 0);
gammaint = interp1(linspace(0, 100, length(gamma)), gamma, t);
loglog(tau,gammaint,'.')
  6 Comments
Torsten
Torsten on 30 Oct 2023
Edited: Torsten on 30 Oct 2023
But the equation says gamma_dot ... Thus you will have to differentiate gamma before you put it in your equation, haven't you ?
gamma = logspace(-3,3,100);
gamma_dot(1) = (gamma(2)-gamma(1));
for i = 2:numel(gamma)-1
gamma_dot(i) = (gamma(i+1)-gamma(i-1))/2;
end
gamma_dot(end+1) = gamma(end)-gamma(end-1);
hold on
plot(gamma)
plot(gamma_dot)
hold off
grid on
Sam Chak
Sam Chak on 17 Nov 2023
Your question looks identical to this one. Can we merge them? If they are not the same, could you please resolve one of them before moving on to the other?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 30 Oct 2023
You have the derivative of tau with respect to t, so tau is a function of t.
You wish to plot tau vs gamma, so tau is also a function of gamma.
When you have something that is a function of two variables, then you have a PDE rather than an ODE. ode45 and the other ode* functions are only for ODE.
You appear to have as in the derivative of gamma, so this appears to have two derivatives -- but you only have one equation. To solve you need as many equations as the sum of the highest derivative order for each variable. First derivative for gamma plus first derivative for tau --> 1 + 1 = 2 so you need two equations.
  1 Comment
Walter Roberson
Walter Roberson on 30 Oct 2023
Moved: Walter Roberson on 30 Oct 2023
syms tau(t) lambda_1 eta_0 gamma__dot
tau__dot = diff(tau);
ode = tau + lambda_1 * tau__dot == - eta_0 * gamma__dot
ode(t) = 
sol = dsolve(ode)
sol = 
Assuming positive lambda_1, the larger t gets, the more the exp() goes to 0 so the more the C_1 term goes to 0. Subtract off the other term and you can certainly go negative. The only way to prevent that is negative lambda_1 or negative product of (eta_0 and gamma__dot) so that you are adding a value instead of subtracting.

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!