필터 지우기
필터 지우기

error on using fplot

조회 수: 18 (최근 30일)
Lorenzo Mereu
Lorenzo Mereu 2021년 3월 8일
댓글: Jorg Woehl 2021년 3월 8일
Hi, I'm new on matlab and maybe this could be a silly answer. I solved this fourth order differential equation, but I have some problems with the function "fplot(usol(x))". Could anyone help me? Thank you! That's the code:
syms u(x) d
a=0.1
Du=diff(u,x)
D2u=diff(u,x,2)
D3u=diff(u,x,3)
ode=diff(u,x,4)==-4*(a^4)*u
c1=u(0)==d
c2=D2u(0)==0
c3=D2u(1)==0
c4=D3u(1)==0
conds=[c1 c2 c3 c4]
usol(x)=dsolve(ode,conds)
usol(x)=subs(usol(x))
fplot(usol(x));
-------------------------------
I report also the error:
Error using fplot>singleFplot (line 240)
Input must be a function or functions of a single
variable.
Error in
fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args)
(line 200)
hObj = cellfun(@(f)
singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 200)
hObj = cellfun(@(f)
singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot (line 166)
hObj =
vectorizeFplot(cax,fn,limits,extraOpts,args);
Error in fourhordertravesuoloelastico (line 18)
fplot(usol(x));

채택된 답변

Jorg Woehl
Jorg Woehl 2021년 3월 8일
편집: Jorg Woehl 2021년 3월 8일
Your solution usol contains two symbolic variables, x and d, but fplot can only deal with functions of a single variable. I suppose that you have forgotten to substitute the value for d, which is probably what you were trying to do in the line usol(x)=subs(usol(x)) - otherwise, this line wouldn't do anything.
For example, this works just fine:
d = 0.2
usol = subs(usol)
fplot(usol)
  댓글 수: 3
Lorenzo Mereu
Lorenzo Mereu 2021년 3월 8일
I have another question: how to plot the solution for some values of "a"? in other words, I want to find some solutions with the parameter "a" that varies, in the same graph
Jorg Woehl
Jorg Woehl 2021년 3월 8일
In this case, you could put your code (except for the fplot line) in a function myfun(a) or even myfun(a, dValue), where you supply the needed numerical values. (Note that if want d to remain a symbolic varialbe inside the function, you need to supply its numerical value using another variable dValue).
function usol = myfun(a, dValue)
syms u(x) d
Du = diff(u, x);
...
d = dValue;
usol = subs(usol);
end
Then call your function multiple times to create your plots and add them all to the same graph:
fplot(myfun(0.1, 0.2));
hold on;
fplot(myfun(second_a_value, 0.2));
fplot(myfun(third_a_value, 0.2));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by