Question

CAN YOU PLEASE CHECK WHATS WRONG? function[F]=func(t,h) global Atank Ahole kOne kTwo g rho %F=zeros(2,1) %NL=y(1)...

CAN YOU PLEASE CHECK WHATS WRONG?

function[F]=func(t,h)
global Atank Ahole kOne kTwo g rho
%F=zeros(2,1)
%NL=y(1)
%NG=y(2)
F=(kOne+kTwo*cos(2*pi*t/24)-rho*Ahole*sqrt(2*g*h))/(rho*Atank);

close all
clear all
%clear all
%close all
global Atank Ahole kOne kTwo g rho

Atank = 3.13;% Atank value
Ahole =0.06; %Ahole value
kOne = 300; % K1 value
kTwo = 200; % K2 value
g = 9.81; % Gravity
rho = 1000; % rho value


t0=0; tf=150; %range of time

%Initial value

h0_2=h(1);
h0_1=h(2);
h0_0=h(3);

n=input('Enter the number of steps:');
dt=(tf-t0)/n; %step size
t=[t0:dt:tf]; %vector of independent variabll (The time)

h0=3 %Initial Height
h=[h0_2; h0_1; h0_0; zeros(n-2,1)];


%Solution (Using Third-order Adam-Bashford Method)

for i=3:n
h(i+1)=h(i)+(dt/12)*(23*func(t(i),h(i))-16*func(t(i-1),h(i-1))+5*func(t(i-2),h(i-2)));
end
plot(t,h,'r')
title('Plot Employing Adams-Bashforth Method');
xlabel('time')
ylabel('Level of Water')

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother function file are not meant to be run directly they are either run through the command window or some script and should be saved with the same name mentioned below. In case of any queries brother just comment in box I would be very happy to assist all your queries.  

========================================

Save file as func.m

========================================

function[F]=func(t,h)
global Atank Ahole kOne kTwo g rho
%F=zeros(2,1)
%NL=y(1)
%NG=y(2)
F=(kOne+kTwo*cos(2*pi*t/24)-rho*Ahole*sqrt(2*g*h))/(rho*Atank);

=======================================

Executable file

=======================================


clc;

close all
clear all
%clear all
%close all
global Atank Ahole kOne kTwo g rho

Atank = 3.13;% Atank value
Ahole =0.06; %Ahole value
kOne = 300; % K1 value
kTwo = 200; % K2 value
g = 9.81; % Gravity
rho = 1000; % rho value


t0=0; tf=150; %range of time

%Initial value

h0_2=0.01;
h0_1=0.02;
h0_0=0.03;

n=input('Enter the number of steps:');
dt=(tf-t0)/n; %step size
t=[t0:dt:tf]; %vector of independent variabll (The time)

h0=3 %Initial Height
h=[h0_2; h0_1; h0_0; zeros(n-2,1)];


%Solution (Using Third-order Adam-Bashford Method)

for i=3:n
h(i+1)=h(i)+(dt/12)*(23*func(t(i),h(i))-16*func(t(i-1),h(i-1))+5*func(t(i-2),h(i-2)));
end
plot(t,h,'r')
title('Plot Employing Adams-Bashforth Method');
xlabel('time')
ylabel('Level of Water')

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
CAN YOU PLEASE CHECK WHATS WRONG? function[F]=func(t,h) global Atank Ahole kOne kTwo g rho %F=zeros(2,1) %NL=y(1)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax...

    MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax T(i)=t; if t>=(T0/2) while (t>T0/2) t=t-T0; end elseif t<=-(T0/2) while (t<=-T0/2) t=t+T0; end end if abs(t)<=(T0/4) y(i)=1; else y(i)=0; end i=i+1; end plot(T,y),grid, xlabel('Time (sec)'); title('y(t) square wave'); shg disp('Hit return..'); pause %--- a0=1/2; F(1)=0; %dc freq C(1)=a0; for n=1:Nmax a(n)=(2/(n*pi))*sin((n*pi)/2); b(n)=0; C(n+1)=sqrt(a(n)^2+b(n)^2); F(n+1)=n*f0; end stem(F,abs,(C)), grid, title(['Line Spectrum: Harmonics = ' num2str(Nmax)]); xlabel('Freq(Hz)'), ylabel('Cn'), shg disp('Hit return...'); pause %--- yest=a0*ones(1,length(T)); for n=1:Nmax yest=yest+a(n)*cos(2*n*pi*T/T0)+b(n)*sin(2*n*pi*T/T0);...

  • Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noi...

    Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noise=5*sin(2*50*3.*t); refer=5*sin(2*50*3.*t+ 3/20); primary=desired+noise; subplot(4,1,1); plot(t,desired); ylabel('desired'); subplot(4,1,2); plot(t,refer); ylabel('refer'); subplot(4,1,3); plot(t,primary); ylabel('primary'); order=2; mu=0.005; n=length(primary) delayed=zeros(1,order); adap=zeros(1,order); cancelled=zeros(1,n); for k=1:n, delayed(1)=refer(k); y=delayed*adap'; cancelled(k)=primary(k)-y; adap = adap + 2*mu*cancelled(k) .* delayed; delayed(2:order)=delayed(1:order-1); end subplot(4,1,4); plot(t,cancelled); ylabel('cancelled');

  • I want to know what is wrong with this code, and how to fix it please....

    I want to know what is wrong with this code, and how to fix it please. i keep getting Error using contour (line 48) Z must be at least a 2x2 matrix. Error in Projectrevised (line 42) curve= contour(b,FOS1,h,'ShowText','on'); %% Constants w = 450000; l = 10; n = 6; SOM = 505000000; max = 10; min = 2; diff = (max-min)/n; FOS1 = zeros(n,n); FOS2 = zeros(n,n); i = 1; j = 1; Vm = (w*l)/2; %% FOS@different base&height...

  • Please answer with Matlab Programming that can be copied and pasted when doing the Matlab part...

    Please answer with Matlab Programming that can be copied and pasted when doing the Matlab part 4 part 2 4. Please finish the following Matlab code for solving the ODE: dy 2(1+t) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: Jon = Y-3 + H25,- fia+2f1-2) h Corrector: Y:-1 =...

  • Can you please help me with this question. Much appreciated. So I have a sample code,...

    Can you please help me with this question. Much appreciated. So I have a sample code, but we need to change the code in a way that fits the problem. A planar slab of material is initially at a temperature of 300 K. At the time t=0, microwave radiation is directed at the material, leading to internal heat generation that is uniform within the material. The sides of the slab experience negligible heat losses and a water bath maintains the...

  • ME 32200 Programming course (MATLAB) 4. Please finish the following Matlab code for solving the ODE:...

    ME 32200 Programming course (MATLAB) 4. Please finish the following Matlab code for solving the ODE: dy = y(1+1) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: 7i+ = Y-3 +h(2f;- fi- +25,-2) Corrector: y = y + + +0. +45j + fi-) Where f; = f(t;,y,) and Fit =...

  • MATLAB code for a double pendulum. Please explain each lines for these codes pls. -------------------------------------...

    MATLAB code for a double pendulum. Please explain each lines for these codes pls. ---------------------------------------------------------------------------- clc close all clear all %---------Parameters------------------------------------------------------ L1=1; L2=1 ; M_1=2 ; M_2=1; G=9.8; %---------initial condition----------------------------------------------- tspan=30; theta1=3; theta1_prime=0; theta2=2.5; theta2_prime=0; y0=[theta1 theta1_prime theta2 theta2_prime]; [t,y]=ode45(@pend, [0 ,tspan],[ 3 0 2 0]); %---position of mass 1 and mass 2---------------------------------------- x1=L1*sin(y(:,1)); y1=-L1*cos(y(:,1)); x2=L1*sin(y(:,1))+l2*sin(y(:,3)); y2=-L1*cos(y(:,1))-l2*cos(y(:,3)); %------visualizing the result--------------------------------------------- figure(1) plot(x1,y1,'linewidth',2) hold on plot(x2,y2,'r','linewidth',2) h=gca; get(h,'fontSize') set(h,'fontSize',14) xlabel('X','fontSize',14); ylabel('Y','fontSize',14); title('Chaotic Double Pendulum','fontsize',14) fh = figure(1); set(fh, 'color', 'white'); figure(2)...

  • 9. MATLAB Problem: Use Matlab to find the convolution y(t) of f(t)2tu(t) and h(t) ut1u(t-1). You ...

    9. MATLAB Problem: Use Matlab to find the convolution y(t) of f(t)2tu(t) and h(t) ut1u(t-1). You should submit a printout of the matlab code as an m-file with comments (using %) explaining the role of each line. You should also submit a plot ofy(t) for-l sts 4. You may find Computer Example C2.4 on page 137 useful EXAMPLE FROM BOOK IS BELOW. System Response to External Input: The Zero-Sta 2.4 QComputer Example C2.4 Find c(t) = f(t) * g(t) for...

  • You are given a finite step function xt=-1  0<t<4 1  4<t<8.           Hand calculate the FS coefficients of...

    You are given a finite step function xt=-1  0<t<4 1  4<t<8.           Hand calculate the FS coefficients of x(t) by assuming half- range expansion, for each case below. Modify the code below to approximate x(t) by cosine series only (This is even-half range expansion). Modify the below code and plot the approximation showing its steps changing by included number of FS terms in the approximation. Modify the code below to approximate x(t) by sine series only (This is odd-half range expansion).. Modify...

  • How can I get my while loop to run until my condition in my if statement...

    How can I get my while loop to run until my condition in my if statement is met? (In MATLAB) clc%clears screen clear all%clears history close all%closes all files format long %Euler's Method %Initial conditions and setup %Projectile motion x=3;%randi(3); y=3;%randi(3); figure('color','white'); plot(x,y,'bo'); hold on wind = (-10 + 20*rand(1)); fprintf('The wind speed is %2.2i\n',wind); v0= input('Initial velocity(m/s): '); a= input('Angle of projection(in degrees): '); a=a*pi/180; h=.01; cd=.1; %cdy=.1; %cdx=(rand*2-1)/2; %cdy=(rand*2-1)/2; m=1.5; g=9.8; %acceleration due to gravity in m/s^2 %td=2*v0*sin(a)/g;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT