Here is my function file:
function dfdeta = mufun(eta,f,T)
pr = 1000;
dfdeta = [f(2); f(3); -f(1) * f(3); T(2); -pr*f(:,1)*T(2)];
end
and here is the code to call my function:
clear;
clc;
close all;
guessf = 0.4696;
guessT = .5;
[eta, f, T] = ode45(@mufun, [linspace(0,6,16)], [0; 0; guessf; 0; guessT]);
plot(eta,f);
blasius = table(eta, f(:,1), f(:,2), f(:,3), 'VariableNames',{'eta','f', 'f prime', 'f double prime'})
I was able to figure out the ode45 for just the eta and f variable, but now I have to have f defined in order to solve for T.

답변 (3개)

James Tursa
James Tursa 2024년 4월 9일
편집: James Tursa 2024년 4월 9일

0 개 추천

Create a new function handle with your extra stuff. E.g.,
mufunT = @(eta,f) mufun(eta,f,guessT)
[eta, f] = ode45(mufunT, [linspace(0,6,16)], [0; 0; guessf]);
But, this assumes you know T in advance. What do you mean by "solve for T"?

댓글 수: 1

Ray
Ray 2024년 4월 9일
We are given a differential equation where these terms: T(2); -pr*f(:,1)*T(2) are needed. We found f previously when we did ode45 without those new terms. But in the differential equation we are given we have to have f(:,1) in order to solve.

댓글을 달려면 로그인하십시오.

Star Strider
Star Strider 2024년 4월 9일

0 개 추천

You have five differential equations and three initial conditions.
The initial conditions vector must have the same length as the number of differential equations.
Beyond that, you need to pass ‘T’ as an additional parameter:
[eta, f] = ode45(@(eta,f)mufun(eta,f,guessT), [linspace(0,6,16)], [0; 0; guessf]);
.

댓글 수: 6

Ray
Ray 2024년 4월 9일
So we do have the initial conditions from the second, so the total initial conditions should be as follows: [0; 0; guessf; 0; guessT]
Star Strider
Star Strider 2024년 4월 9일
I don’t udnerstand what you are doing.
If you define the initial conditions the way you described in your latest Comment (that should work with respect to your differential equations), you likely do not need to pass ‘T’ as an additional parameter. However, since I do not understand what you want to do, I will defer to you to determine that.
Ray
Ray 2024년 4월 9일
I have 2 second order differential equations, the first one we solve for the 3 initial conditions in terms of f. So now i have another question based on the outputs of the first second order differential equation which are in terms of T: T(2); -pr*f(:,1)*T(2) as you can see here I have f(:,1) multiplied by other variables, this is the where the trouble is. I cannot store f in a function file so therefore it is not defined and I cannot solve it. I also tried calling it as an annonymous function and the vector lengths did not align.
Star Strider
Star Strider 2024년 4월 10일
I can’t even guess what you want to do from what is currently posted.
See ODE with Time-Dependent Terms for one possible approach.
James Tursa
James Tursa 2024년 4월 10일
@Ray Can you post an image of the differential equations you are trying to solve?
Ray
Ray 2024년 4월 10일
It has to be as a pdf, the images came out wrong. Hope this makes sense.

댓글을 달려면 로그인하십시오.

Torsten
Torsten 2024년 4월 10일
편집: Torsten 2024년 4월 10일

0 개 추천

You have to define your vector of solution variables as
y(1) = f, y(2) = f', y(3) = f'', y(4) = T, y(5) = T'
and your function as
function dydeta = mufun(eta,y)
pr = 1000;
dydeta = [y(2); y(3); -y(1)*y(3)/2; y(5); -pr/2*y(1)*y(5)];
end
Further, your problem is a boundary value problem, not an initial value problem. Use "bvp4c", not "ode45" to solve.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

태그

질문:

Ray
2024년 4월 9일

편집:

2024년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by