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

  • Thread starter Thread starter Cornelius
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion focuses on modifying MATLAB code to ensure that peaks in a simulation occur near the middle rather than at the boundaries. The user is struggling with the line calculating the end value of "u" and has attempted to use "end/2" to adjust the peak position, but this has not yielded satisfactory results. They seek guidance on how to correctly implement this adjustment and also inquire about calculating the value of "u" at a specific location within the simulation. The conversation highlights the need for precise coding techniques to achieve desired outcomes in numerical simulations. The user is looking for effective solutions to these coding challenges.
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.
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top