previous technique didnt work for the present code

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 件のコメント

Rik
Rik 2019 年 2 月 24 日
編集済み: Rik 2019 年 2 月 24 日
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
MINATI 2019 年 2 月 24 日
I want to draw
  1. u(:,4) w.r.t t (in X-axis) first
  2. 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
MINATI
MINATI 2019 年 2 月 25 日
編集済み: MINATI 2019 年 2 月 25 日
Dear STAR
could you please interfere with the code. It is taking too much of time to run with no output. It is in extended form of previous code(before 3 days)
Jan
Jan 2019 年 2 月 25 日
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
MINATI 2019 年 2 月 26 日
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
Jan 2019 年 2 月 26 日
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
MINATI 2019 年 2 月 26 日
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
Jan 2019 年 2 月 26 日
編集済み: Jan 2019 年 2 月 26 日
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
MINATI 2019 年 2 月 26 日
編集済み: MINATI 2019 年 2 月 26 日
Dear Jan
it takes so much of run time that I have to exit.
Again same thing happened for your modified code.
MINATI
MINATI 2019 年 2 月 26 日
%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.
MINATI
MINATI 2019 年 2 月 26 日
Pl. Jan put a last try. of course at your time.
Thanks!
Jan
Jan 2019 年 2 月 26 日
"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
MINATI 2019 年 2 月 26 日
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
Jan 2019 年 2 月 26 日
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.
MINATI
MINATI 2019 年 2 月 26 日
編集済み: MINATI 2019 年 2 月 26 日
No we will run normally and then we change the value of x (manually).
I can handle that part but thing is first the code should run
Extension of the given code in the video:(for reference)
https://www.youtube.com/watch?v=eSdebB_oyMM
Jan
Jan 2019 年 2 月 26 日
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
MINATI 2019 年 2 月 27 日
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
Jan 2019 年 2 月 27 日
@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
MINATI 2019 年 2 月 27 日
ok Jan
I had created a new one
https://in.mathworks.com/matlabcentral/answers/questions/new/?s_tid=gn_mlc_ans_ask
Jan
Jan 2019 年 2 月 27 日
@MINATI: This is a link to asking a new question, but not to your new question.
Walter Roberson
Walter Roberson 2019 年 2 月 27 日
Probably this one

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2019 年 2 月 24 日

コメント済み:

2019 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by