previous technique didnt work for the present code
1 次查看(过去 30 天)
显示 更早的评论
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
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
2019-2-24
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
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
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
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
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
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
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.
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
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
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.
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
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
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
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with MuPAD 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)