A GUI that takes in input and solves a set of ODEs

2 views (last 30 days)
This is a homework assignment so I don't want anyone to write code for me, but I'm tasked with building a fairly complex GUI using GUIDE and I have no experience with that part of MATLAB. I've spent the last hour or so reading GUI materials, but I still don't know how to approach the GUI aspect of this problem.
The first part was easy: I've written a function (included below) that solves the Blasius solution and includes a thermal boundary layer. It then plots the two solutions (the Blasius boundary layer and the thermal boundary layer).
What I want my GUI to do is take the Prandtl number, Pr, and Eta_max, etaMax, as user inputs in a text box, and graph the results with a button press.
So, here's my main question, in two parts:
1. Where in the code do I insert my function? 2. I've designed my GUI using the UI, but how do I share variables between the input text box and the plot, for example?
Thank you in advance for your help!
function thermalboundary
Pr = [.07]; % Choose Prandtl
etaMax = [15]; % Choose etaMax
xm = [15];
figure;
solinit = bvpinit(linspace(0,etaMax,8),...
[0, 0, 0, 0, 0]);
sol = bvp4c(@BlasiusT, @BlasiusTbc,...
solinit, [], Pr);
eta = linspace(0, etaMax);
y = deval(sol, eta);
subplot(2, 1, 1);
plot(eta, y(1,:),'--k',eta,y(2,:),'-k',eta,...
y(3,:),':k');
xlabel('\eta');
ylabel('y_1, y_2, y_3');
legend('Stream function f = y_1',...
'Velocity, df/d\eta = y_2', ...
'Shear, d^2f/d\eta^2 = y_3');
axis([0 xm 0 2]);
subplot(2, 1, 2);
plot(eta, y(4,:), '--k', eta, y(5,:), ':k');
axis([0 xm 0 2]);
legend('Temperature, T^* = y_4',...
'Heat flux, dT^*/d\eta = y_5');
xlabel('\eta');
ylabel('y_4, y_5');
function F = BlasiusT(eta, y, Pr)
F = [y(2); y(3); -0.5*y(1)*y(3); y(5); ...
-Pr*0.5*y(1)*y(5)];
function res = BlasiusTbc(ya, yb, Pr)
res = [ya(1); ya(2); ya(4); yb(2)-1; yb(4)-1];

Accepted Answer

Joseph Cheng
Joseph Cheng on 24 Apr 2015
One of the best ways to get started to learning GUIDE is to look at the basic examples that they have. When you just type in "guide" open up the quick start template "GUI with Uicontrols" there it'll show a simple example of what the calculate button does if you scroll down to the calculate_callback [which is the function that will be run when the button is clicked]. Which grabs the inputs from what was input for density and what was input in volume to be calculated and displayed as text.
So to explain where you paste your code above you'd just paste it at the end of the GUIDE m file. and call thermalboudary within the calculate button. you'd need to set outputs in your thermalboundary function. think of it as the GUIDE m file is the main function and everything else is additional calls within that main function. Just as your thermalboundary is in your code above and you then use the other functions inside of it.
You could also paste the code in the main thermalboundary function in the calculate button callback and then the other two functions blasiusT and blasiustbc at the end or right after the button callback.
Without coding something for you or something quick as an example, the Quick start templates and searching online for the specific thing you want to do will get your answer.
  2 Comments
Joseph Cheng
Joseph Cheng on 24 Apr 2015
just to expand a bit more. if you have an edit box you'd get its contents by using the get command. The template i discuss above does show how to use it.
the GUI with AXES and Menu template is another good example on how to send things to the plot axes.
If you do need to pass variables between callbacks you're best bet is to store them within the handles structure. This is a global variable that is shared in all the UI items. (i'm not sure if i'm describing it correctly as a global variable but its very late here) if you store it within that structure you can retrieve the data elsewhere.
KMill
KMill on 28 Apr 2015
Thank you, this is exactly the kind of advice I was looking for. I had to play around with the handles structure for a while but I finally got it to work.
Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!