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

  • Thread starter Thread starter Cornelius
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

This discussion focuses on modifying MATLAB code to ensure that peaks in a simulation occur near the center of the graph, rather than at the boundaries. The user is working with a variable 'u' initialized to 1000 and is attempting to adjust the calculation of 'u' at the boundaries using the expression 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. Additionally, the user seeks guidance on how to compute the value of 'u' at a specific location within the simulation.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of numerical methods for differential equations
  • Knowledge of the 'diff' function in MATLAB
  • Basic concepts of logarithmic functions and their applications in simulations
NEXT STEPS
  • Research MATLAB's 'diff' function for advanced applications
  • Explore techniques for manipulating boundary conditions in numerical simulations
  • Learn about peak detection algorithms in MATLAB for data analysis
  • Investigate methods for calculating specific values in arrays or matrices in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB programmers, numerical analysts, and researchers involved in computational simulations, particularly those focusing on differential equations and peak analysis in data visualization.

Cornelius
Messages
4
Reaction score
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
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?
 
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.
 

Similar threads

Replies
2
Views
2K
Replies
2
Views
2K
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K