plotting two curves together in one graph for different intervals

11 vues (au cours des 30 derniers jours)
Hi,
I have two functions that I want to plot for differnt intervals. I wrote a code but the output is kinda wiered. Can someone please help me what I am doing wrong with the code?
My functions are:
f(x1)= 22528*((0.2808-0.1031)*x +(0.1666-0.2808)*(144728064/(22528-x))+0.2808*(72982528/x)+0.1031*(22528)) from [0 to 7552.2278]
f(x2)= 22528*((0.2808-0.1031)*x +(0.1666-0.1031)*(72982528/x)+0.1031*(144728064/(22528-x))+0.1031*(22528)) from [7552.2278 to 22528]
I wrote below code but got strange output,
y_1 = @(x) 22528.*((0.2808-0.1031).*x +(0.1666-0.2808).*(144728064 ./(22528-x))+0.2808.*(72982528./x)+0.1031.*(22528))
y_2 = @(x) 22528.*((0.2808-0.1031).*x + (0.1666-0.1031).*(72982528./x)+0.1031.*(144728064./(22528-x))+0.1031.*(22528))
x_1 = 0:0.1:7552.2278; // y_1 Interval
x_2 = 7552.2278:0.1:22528; //y_2 Interval
plot(x_1,y_1(x_1),'b',x_2,y_2(x_2),'b')
Please help me what I am doing wrong? Also I want to get all minimum points how I write the code for that?
  1 commentaire
Tania Malik
Tania Malik le 12 Mai 2020
I think the problem was my increment value. I changed it to 100 and got result. Now my question is how to get the minimum of this single curve?

Connectez-vous pour commenter.

Réponse acceptée

Johannes Hougaard
Johannes Hougaard le 12 Mai 2020
Hi Tania
When plotting a function you've already described as a function handle I'd use fplot rather than plot.
As far as I can see this will do the trick
y_1 = @(x) 22528.*((0.2808-0.1031).*x +(0.1666-0.2808).*(144728064 ./(22528-x))+0.2808.*(72982528./x)+0.1031.*(22528));
y_2 = @(x) 22528.*((0.2808-0.1031).*x + (0.1666-0.1031).*(72982528./x)+0.1031.*(144728064./(22528-x))+0.1031.*(22528));
x_1 = [0 7552.2278]; % y_1 Interval
x_2 = [7552.2278 22528]; % y_2 Interval
figure;
fplot(y_1,x_1);
hold on
fplot(y_2,x_2);
Regarding the minimum I can't seem to find a minimum for y_1 but for y_2 the minimum is found by using fminsearch
x_min = fminsearch(y_2,min(x_2));
  2 commentaires
Tania Malik
Tania Malik le 12 Mai 2020
Thank you! I got the nice graph. Is there any way I can get the minimum point considering it as a single curve?
Johannes Hougaard
Johannes Hougaard le 12 Mai 2020
To do that I'd create a separate function (see attached myfun) and use the fminsearch option
x_min = fminsearch(@myfun,mean([x_1,x_2]))
But you've pretty much found it yourself in the intersect between your x-ranges.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by