You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
previous technique didnt work for the present code
1 view (last 30 days)
Show older comments
function main
so=1;
c=-1.25;
% a=1;
Pr=1;
%n=2;
n=input('n=') %%n=-0.3,-0.5
x=[1 1];
x1=fsolve(@solver,x);
function F=solver(x)
[t,u]=ode45(@equation,[0,20],[so c 1 x]);
s=length(t);
F=[u(s,2)-1; u(s,4)];
end
figure(1)
plot(t,u(:,4),'b-');
hold on
function dy=equation(t,y)
dy=zeros(5,1);
dy(1)=y(2);
dy(2)=y(3);
dy(3)=y(2)^2-y(1)*y(3)-1;
dy(4)=y(5);
dy(5)=Pr*(n*y(2)*y(4)-y(1)*y(5));
end
end
ERROR is
code is not running
21 Comments
Rik
on 24 Feb 2019
Edited: Rik
on 24 Feb 2019
Since you don't have any comments, I don't have a clue what your goal is. But the source of your problem is that you call the solver with 4 elements in y, but inside the solver you assume that there are 5.
Also, you seem to be repeating the same code several times, as well as repeating the nested function equation. And the clc;clear all; at the beginning of your code is useless (or at least the clear all is, since a function will start with an empty workspace anyway (unless you have input variables).
MINATI
on 24 Feb 2019
I want to draw
- u(:,4) w.r.t t (in X-axis) first
- u(:,4) w.r.t Pr (in X-axis, continuous range, say, from 0 to 7) and for different values of so=1,2,3
N.B: Dual solution concept so program is repeated
Thanks in advance
Jan
on 25 Feb 2019
By the way: a clear all is a complete waste of time on top of a function. Why clearing an empty workspace? Removing all functions from the memory wastes time with reloading them from the slow disk.
MINATI
on 26 Feb 2019
Dear Jan
Can we proceed with the code.
Yeh actually the lines makes no role in code but I am running the code repeatedly but to avoid confusion with previous ERROR msg.
Pl. help here
Jan
on 26 Feb 2019
The clear all does not avoid confusion, but is useless only. Keeping two functions with the same name and contents in the same file is confusing also, even if they are on different levels of nesting. This does not look like a "Dual solution concept", but like obfustcation. As you see, such tricks impede the debugging.
MINATI
on 26 Feb 2019
Dear Jan
First Thanks for your valuable time and suggestion
According to your suggestion I have somehow corrected my fault but still the code is not running. What to do now?
Jan
on 26 Feb 2019
Edited: Jan
on 26 Feb 2019
As far as I understand, you want to run this:
function main
so = 1;
c = -1.25;
Pr = 1;
n = 2;
x = [1, 1];
x1 = fsolve(@solver, x);
[t, u] = ode45(@equation,[0,20], [so, c, x1(1), 1, x1(2)]);
figure(1)
plot(t, u(:,4), 'b-');
hold on
function F = solver(x)
disp(datestr(now, 0))
[t, u] = ode45(@equation, [0, 20], [so, c, 1, x]);
F = [u(end, 2) - 1; u(end, 4)];
end
function dy = equation(t, y)
Pr = 1;
dy = zeros(5,1);
dy(1) = y(2);
dy(2) = y(3);
dy(3) = y(2)^2 - y(1) * y(3) - 1;
dy(4) = y(5);
dy(5) = Pr * (n * y(2) * y(4) - y(1) * y(5));
end
end
"Is not running" does not explain, what you observe. Please post this.
It is hard to modify the code, because you did not tell us, what the code should do. A not runnming piece of code keeps its purpose as secret, if the programmer did not inset exhaustive comments.
MINATI
on 26 Feb 2019
%Here is the qn with B.C for REF:(Dual solu needed)
f'''+ff''-(f')^2+1=0,
g''+Pr[fg'-nf'g]=0,
%f(0)=so,f'(0)=c,f'(inf)=0,
g(0)=1,g(inf)=0.
Jan
on 26 Feb 2019
"it takes so much of run time" - please tell us any details: How much time does it need and what do you expect?
"Here is the qn with B.C for REF:(Dual solu needed)" - this sounds like pure magic to me. Please care for the non-native speakers like me and use full english words. Thank you.
MINATI
on 26 Feb 2019
I have given the differential equation:
f'''+ff''-(f')^2+1=0,
g''+Pr[fg'-nf'g]=0,
with initial and boundary conditions
f(0)=so,f'(0)=c,f'(inf)=0,
g(0)=1,g(inf)=0.
After running the code for one value of x, say 1, we will get one solution and then we need to change the value of x,say , for 5, another solution(dual) came into picture.
Jan
on 26 Feb 2019
I cannot run this code "for one value of x", because the formula does not contain any "x". Therefore I do not know, what changing its value to 5 is any kind of "dual". You cannot implement boundary conditions at Inf.
Jan
on 26 Feb 2019
Sorry, MINATI, I do not get what you want to do. In your comment above (link) you wrote "running the code for one x", but the formula does not contain any "x". Then the explanation "we change the value of x (manually)" does not clarify my question.
MINATI
on 27 Feb 2019
First we run the program with x=[1, 1] ; we will get one curve, keeping the curve, we need to change x=[1, 0] OR x=[2, 1] some thing like this.
Please for reference follow this video: https://www.youtube.com/watch?v=eSdebB_oyMM
Jan
on 27 Feb 2019
@MINATI: Again and for the last time: The formula you have posted does not contain an "x". So you cannot run it with different values for x.
It is not efficient, if I watch internet videos about your problem, because it is your turn to understand the mathematical problem. This forum cares about the implementation in Matlab only. It is not clear to me, what the actual question is and you react to my questions for clarifications by repeating the formerly posted statements. This does not make the problem clear.
I suggest to drink a cup of coffee. Reformulate the problem. Post a minimal example, which demonstrates the problem and explain clearly, what you want to solve and what you observe. Maybe opening a new thread is a good idea, because this one is confusing now. If you do so, mention this thread as a link.
MINATI
on 27 Feb 2019
ok Jan
I had created a new one
https://in.mathworks.com/matlabcentral/answers/questions/new/?s_tid=gn_mlc_ans_ask
Answers (0)
See Also
Categories
Find more on Get Started with MuPAD 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)