現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)