The graph doesn't disply

2 Ansichten (letzte 30 Tage)
재훈
재훈 am 22 Mai 2024
Kommentiert: Star Strider am 22 Mai 2024
Sorry for repeating the question so many times. I try to display the graph, but the marked part does not appear. Can you help me?
clc; clear all; close all;
fun =@(t) (1/200).*t.^2+(1/500).*exp(-0.2.*t)+5;
dgraph = @(point, dfda, t) dfda*t + (fun(point)-dfda*point);
est_point=150;
da=2;
dfda_true=(1/100).*(150)+(-0.2./500).*exp(-0.2.*(150));
dfda_forward = (fun(est_point+da)-fun(est_point))./da;
dfda_backforward=(fun(est_point)-fun(est_point-da))./da;
dfda_center=(fun(est_point+da)-fun(est_point-da))./(2.*da)
a=-50:0.01:150;
figure(1)
plot(a,fun(a),'k'); hold on;
plot(a, dgraph(est_point,dfda_true,a),'b'); hold on; %dosen't work
plot(a, dgraph(est_point,dfda_center,a),'r'); hold on;

Akzeptierte Antwort

Star Strider
Star Strider am 22 Mai 2024
It actually does work. The problem is that the red line overplots it since it is plotted later, and hides the blue line. If you make the blue line wider (I set 'LineWidth',3 here) the blue line shows up.
Try this —
% clc; clear all; close all;
fun =@(t) (1/200).*t.^2+(1/500).*exp(-0.2.*t)+5;
dgraph = @(point, dfda, t) dfda*t + (fun(point)-dfda*point);
est_point=150;
da=2;
dfda_true=(1/100).*(150)+(-0.2./500).*exp(-0.2.*(150));
dfda_forward = (fun(est_point+da)-fun(est_point))./da;
dfda_backforward=(fun(est_point)-fun(est_point-da))./da;
dfda_center=(fun(est_point+da)-fun(est_point-da))./(2.*da);
a=-50:0.01:150;
figure(1)
plot(a,fun(a),'k'); hold on;
plot(a, dgraph(est_point,dfda_true,a),'b', 'LineWidth',3); hold on; %dosen't work
plot(a, dgraph(est_point,dfda_center,a),'r'); hold on;
.
  2 Kommentare
재훈
재훈 am 22 Mai 2024
Thank you so much for your help. have a good day! cheers:)
Star Strider
Star Strider am 22 Mai 2024
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by