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?
plotting two curves together in one graph for different intervals
11 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
Johannes Hougaard
2020-5-12
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 个评论
Johannes Hougaard
2020-5-12
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.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!