Finding the x that makes y minimum in MATLAB.

In summary, in this conversation, the individuals discuss how to use MATLAB to find a minimum of a function in terms of x and how to plot multiple data series on the same xy plot using a single written program. They mention using functions such as diff() and polyder() to manipulate the data and suggest using a for loop and hold off to plot multiple data series.
  • #1
btbam91
91
0
Hello.

As stated in the title, I have a function y that is in terms of x. How do I go about determing the 'x' that makes 'y' a minimum?

Thanks!
 
Physics news on Phys.org
  • #2
Think calculus: how can you find a minimum of a function? Then, it's just a matter of telling MATLAB to do this.
 
  • #3
Duhhh, I guess I was just being lazy and expecting a MATLAB function to handle it for me.

Thanks!
 
  • #4
Hi
Is there anyone help me with Matlab
I have got different data series of x and y, and want to plot them in a single xy plot using a single written program, can you advice?
Emmanuel
 
  • #5
@btbam91:
If you have data in vector form, you can use diff() or polyder(). You might actually be able to do:
Code:
[yMin I] = min(y)
% corresponding x is:
x(I)
Symbolically, you can use diff() and then solve().

@manyoolo:
"hold on" will allow multiple data to be plotted on the same plot.
 
  • #6
manyoolo said:
Hi
Is there anyone help me with Matlab
I have got different data series of x and y, and want to plot them in a single xy plot using a single written program, can you advice?
Emmanuel

This:
plot(x1,y1,x2,y2,x3,y3);

or if all x and y's are same length:
plot( [ x1 x2 x3 ], [ y1 y2 y3]);

or as already mentioned:
plot(x1, y1);
hold on;
plot(x2, y2);
plot(x3, y3);
hold off;
 
  • #7
jhae2.718 said:
@btbam91:
If you have data in vector form, you can use diff() or polyder(). You might actually be able to do:
Code:
[yMin I] = min(y)
% corresponding x is:
x(I)
Symbolically, you can use diff() and then solve().

@manyoolo:
"hold on" will allow multiple data to be plotted on the same plot.[/QUO

Dear
This is what I have
h=4.14*10^-15;%eV.s
c=3*10^8%m/s^2
d=124.38*10^-9%m;
lambda= (W50)*10^-9%m
T=T50./100;
y=-(log(T));
alpha=y*(1/d);
nu=(1./lambda).*c;
A=nu.*(alpha).*(h);
D=sqrt(A)
B=nu.*(h);
%plot (B,D, 'om')

hold on
h=4.14*10^-15;%eV.s
c=3*10^8%m/s^2
d=93.06*10^-9%m;
lambda= (W47)*10^-9%m
T=T47./100;
y=-(log(T));
alpha=y*(1/d);
nu=(1./lambda).*c;
A=nu.*(alpha).*(h);
D=sqrt(A)
B=nu.*(h);
%plot (B,D, 'og')

this programs give me good plots in single xy plane
AND my goal is to write only one program in which the program will be able to go and pick the data series ie (W50,T50), (W47, T47)...and plot the graphs without necessarily repeat writing the program for each data series
Hope you got my point
 
  • #8
manyoolo said:
this programs give me good plots in single xy plane
AND my goal is to write only one program in which the program will be able to go and pick the data series ie (W50,T50), (W47, T47)...and plot the graphs without necessarily repeat writing the program for each data series
Hope you got my point

Use a for loop and place hold off at the end.
 

FAQ: Finding the x that makes y minimum in MATLAB.

1. How do I find the x value that makes y minimum in MATLAB?

To find the x value that makes y minimum in MATLAB, you can use the fminsearch function. This function will search for the minimum value of a given function by varying the input parameters.

2. Can I specify a range of values to search for the minimum x value in MATLAB?

Yes, you can specify a range of values to search for the minimum x value using the fminbnd function. This function will search for the minimum value within a specified interval.

3. How can I visualize the minimum x value and corresponding y value in MATLAB?

You can use the fminsearch function to find the minimum x value and then plot the corresponding y value on a graph using the plot function.

4. Is there a way to find the minimum x value for multiple y values in MATLAB?

Yes, you can use a loop to iterate through different y values and use the fminsearch function to find the minimum x value for each y value.

5. Can I use the fminsearch function for non-linear functions in MATLAB?

Yes, the fminsearch function can be used for non-linear functions. However, it may not always guarantee the global minimum and may get stuck at a local minimum. It is important to carefully choose the starting point and check the results for accuracy.

Similar threads

Replies
1
Views
1K
Replies
1
Views
1K
Replies
10
Views
2K
Replies
2
Views
1K
Back
Top