Needs derivative w.r.t. ' y ' & then graph w.r.t ' t '

2 Ansichten (letzte 30 Tage)
MINATI
MINATI am 12 Mai 2019
Kommentiert: MINATI am 16 Mai 2019
y=0:0.01:5;
P2=5; %%% t=1;
U=exp(y*sqrt(P2)).*(1-erf(y./(2.*sqrt(t))+ sqrt(P2.*t)));
S= - diff(U,y); %%Needs derivative w.r.t. ' y ' & then its value at y=0
F= - diff(U,1);
%%NOW need to graph w.r.t ' t '
t=0:0.01:5;
plot(t,F)
xlabel(' t');
ylabel('F');
While running the code the following error occurs:
The second argument must be a variable or a nonnegative integer specifying the number of differentiations.
Error in
S= - diff(U,y)
And for F= - diff(U,1)
F=[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] is coming which is of no interest.
  2 Kommentare
gonzalo Mier
gonzalo Mier am 12 Mai 2019
Can you edit your question to put your code in code format?
Like this
MINATI
MINATI am 12 Mai 2019
Actually I don't know how to do that

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

gonzalo Mier
gonzalo Mier am 12 Mai 2019
Bearbeitet: gonzalo Mier am 12 Mai 2019
diff is a function of the symbolic package, so when you try to derivate U, you are derivating a constant, and by a constant, so F is a 0. To do what you want, you should do it in symbolic and then replace your variable, like:
syms y t
P2=5;
U=exp(y*sqrt(P2)).*(1-erf(y./(2.*sqrt(t))+ sqrt(P2.*t)));
S= - diff(U,y);
v_t=0.01:0.01:5;
F = subs(S,y,0);
plot(v_t,vpa(subs(F,t,v_t)))
xlabel(' t');
ylabel('F');
  7 Kommentare
gonzalo Mier
gonzalo Mier am 15 Mai 2019
Oh sorry, I hope you and your family are ok.
Once a week I just see the answers I have answer that week and clean the ones that were accepted or comment the ones that seems solved. Sorry if it was too soon.
Thank you for accepting my answer and my best wishes for you.
MINATI
MINATI am 16 Mai 2019
oh Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by