Ensuring Peaks Near Middle & Calculating End Value of "u" in MATLAB

  • Thread starter Cornelius
  • Start date
  • Tags
    Matlab
In summary, you need to clear all variables, close all plots, and calculate the value of u at the given point using the end/2 expression.
  • #1
Cornelius
4
0
1. In the below code, I need to know how to ensure that the peaks end up near the middle. I also want to know how to calculate the end value of "u". Thanks!



2.
clear all
close all
clc

u = 1000*ones(1,200);
dt = 0.01;
dx = 1/201;
for i = 2:10/dt
dudt = diff(u(i-1,:));
Du = 10*log(10*exp(-0.0001*u(i-1,:)));
dudt = diff(Du(1:end-1).*dudt);
u(i,:)= u(i-1,:);
u(i,2:end-1) = u(i,2:end-1)+dudt*dt;
u(i,1) = u(i,2)-10*(log(10*exp(-0.0001*u(i,1))))*(1-(log(10*exp(-0.0001*u(i,1))))/100)*dx;
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

hold on
plot(u(i,:))
end




3. I tried using "end/2" in the above expression, but it doesn't give me a suitable solution.
 
Physics news on Phys.org
  • #2
Cornelius said:
1. In the below code, I need to know how to ensure that the peaks end up near the middle. I also want to know how to calculate the end value of "u". Thanks!



2.
clear all
close all
clc

u = 1000*ones(1,200);
dt = 0.01;
dx = 1/201;
for i = 2:10/dt
dudt = diff(u(i-1,:));
Du = 10*log(10*exp(-0.0001*u(i-1,:)));
dudt = diff(Du(1:end-1).*dudt);
u(i,:)= u(i-1,:);
u(i,2:end-1) = u(i,2:end-1)+dudt*dt;
u(i,1) = u(i,2)-10*(log(10*exp(-0.0001*u(i,1))))*(1-(log(10*exp(-0.0001*u(i,1))))/100)*dx;
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

hold on
plot(u(i,:))
end



3. I tried using "end/2" in the above expression, but it doesn't give me a suitable solution.

Which "above expression"? Which line is causing you problems, and what exactly are the problems?
 
  • #3
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

that is the line that is giving me problems. Basically, when I run this simulation I get peaks occurring at the boundaries - instead, I want peaks to occur in the centre. Can I do this by the following code?

u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end/2))))*(1-(log(10*exp(-0.0001*u(i,end/2))))/100)*dx;

?

Also, if I wanted to compute the value of u at a particular place, how would I do that? Thanks a lot.
 

1. How do I ensure that the peaks are near the middle of my data when using MATLAB?

To ensure that the peaks are near the middle of your data in MATLAB, you can use the findpeaks function. This function will locate the peaks in your data and return their corresponding indices. You can then use these indices to shift your data so that the peaks are in the middle.

2. How can I calculate the end value of "u" in MATLAB?

To calculate the end value of "u" in MATLAB, you can use the max function. This function will return the maximum value in a given array. You can then use this value to determine the end value of "u" in your data.

3. Is there a built-in function in MATLAB for finding peaks?

Yes, there is a built-in function in MATLAB for finding peaks. It is called findpeaks and it can be used to locate and return the indices of peaks in your data.

4. Can I use MATLAB to shift my data so that the peaks are in the middle?

Yes, you can use MATLAB to shift your data so that the peaks are in the middle. As mentioned earlier, you can use the findpeaks function to locate the peaks and their corresponding indices. You can then use these indices to shift your data using the circshift function.

5. What is the purpose of ensuring that peaks are near the middle of my data?

Ensuring that peaks are near the middle of your data can help with visualizing and analyzing the data. It can also make it easier to compare different datasets and identify any patterns or trends that may exist. Additionally, it can be useful for performing further analysis or calculations on the data.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
826
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Differential Equations
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top