Question

fix this code for me in math lab and get it to produce a graph and...

fix this code for me in math lab and get it to produce a graph and send me the new code and picture of the graph. I defined all the equations and constants already, I just can't get it to work and I need help.

code :

clear;clc;

t0=0;tf=100;

y0=[1;2]; % input spec ((y(1)- F_1; y(2)-H_1; y(3)- H_3;

soln=ode45(@f,[t0,tf],y0); %Solve the set of ODEs

t=linspace(t0,tf,100); %create x axis spacing

y1=deval(soln,t,1); %get value for y1 @ all t

y2=deval(soln,t,2); %get value for y2 @ all t

plot(t,y1,'k-',t,y2,'k--'); %plot it. y2 is dashed

xlabel('t(s)');

ylabel('tank level(m)');

end

%NOTE: Matlab fundamentally works with matrices, so lines 8-10 work on the

%entire solution set as soon as they're executed. (ie. no loops needed)

function dYdt= f(t,y)

tauv = 3;

F_outspec=0.06684028; %ft3/s

H_1 = 5;

H_2 = 5;

H_d = 2;

A_1 = 15;

A_2 = 20;

K_1 = 1 ;

K_2 = 1 ;

if t>= 400; F_outspec = 0.07352431 ;

end

dYdt(1) = ( F_outspec - y(1))/tauv;

dYdt(2) = ((y(1)/A_1) - (K_1*((H_1 +H_d + H_2)^0.5)/A_1));

dYdt(3) = ((K_2*(H_1 +H_d - H_2)^0.5) - (K_2 * (H_2)^0.5))/A_2 ;

dYdt=dYdt'; %return dYdt as column vector

end

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

There are two issues with the code:

1) An extra "end" after the ylabel as:

ylabel('tank level(m)');

end ------------> Remove this!!

2) You initial condition set is having only two values for y0 written as:

y0=[1;2]; --------> add one more entry as per the given details for your question, the program works fine!!

For example see the following execution: (Note: we have added a third entry (3) randomly, you need to update the same as per given in original question!)

%===================================================

clc;
clear all;
format long


clear;clc;

t0=0;
tf=100;

y0=[1;2;3]; % input spec ((y(1)- F_1; y(2)-H_1; y(3)- H_3;

soln=ode45(@f,[t0,tf],y0); %Solve the set of ODEs

t=linspace(t0,tf,100); %create x axis spacing

y1=deval(soln,t,1); %get value for y1 @ all t

y2=deval(soln,t,2); %get value for y2 @ all t

plot(t,y1,'k-',t,y2,'k--'); %plot it. y2 is dashed

xlabel('t(s)');

ylabel('tank level(m)');

%NOTE: Matlab fundamentally works with matrices, so lines 8-10 work on the

%entire solution set as soon as they're executed. (ie. no loops needed)

function dYdt= f(t,y)

tauv = 3;

F_outspec=0.06684028; %ft3/s

H_1 = 5;

H_2 = 5;

H_d = 2;

A_1 = 15;

A_2 = 20;

K_1 = 1 ;

K_2 = 1 ;

if t>= 400; F_outspec = 0.07352431 ;

end

dYdt(1) = ( F_outspec - y(1))/tauv;

dYdt(2) = ((y(1)/A_1) - (K_1*((H_1 +H_d + H_2)^0.5)/A_1));

dYdt(3) = ((K_2*(H_1 +H_d - H_2)^0.5) - (K_2 * (H_2)^0.5))/A_2 ;

dYdt=dYdt'; %return dYdt as column vector

end

%==============================================

output plot:

Add a comment
Know the answer?
Add Answer to:
fix this code for me in math lab and get it to produce a graph and...
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
  • help me with this. Im done with task 1 and on the way to do task...

    help me with this. Im done with task 1 and on the way to do task 2. but I don't know how to do it. I attach 2 file function of rksys and ode45 ( the first is rksys and second is ode 45) . thank for your help Consider the spring-mass damper that can be used to model many dynamic systems -- ----- ------- m Applying Newton's Second Law to a free-body diagram of the mass m yields the...

  • I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT...

    I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT WE HAVE A SUB AND HE DIDN'T TEACH IT! ITS EULER AND IMPROVED EULER IN MATLAB! HERE IS THE LINK FOR THE IMAGE FILE THAT SHOWS THE FULL INSTRUCTIONS FOR THE CODE. https://imgur.com/a/gjmypLs Also, here is my code so far that I borrowed form an old assignment but the data is all wrong and the application of the code is slightly different so either...

  • 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)...

  • Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current...

    Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current program stops the animation and then has the crank move backward. I need the crank to instead to move in full 360 degrees circular motion. Exactly like how a slide-crank mechanism works in real life. thank you and here is the code. %%Code Begins Here%% L1=0.2; L2=0.45; W=0.5; tt=linspace(0,15); for i=1:length(tt)     x2=@(t) L2+L1*sin(W*t);     y2=0;     X2=x2(tt(i));     Y2=y2;     sol= fsolve(@(x,x2,y2) root2d(x,X2,Y2),...

  • please code on MATHLAB and show graph thank you in advance! Generate the following function y1(t)=2*...

    please code on MATHLAB and show graph thank you in advance! Generate the following function y1(t)=2* sin (2*pi* 1 *t)+4*sin(2*pi*2*t)+3*sin(2*pi*4*t) y2(t)=2*cos(2*pi*1*t)+4*cos(2*pi*2*t)+3*cos(2*pi*4*t) First, required by sampling theorem, the step size of t (delta t) has to be smaller than a value. Figure out this value and set the delta t at least 3 times smaller than this value and calculated y1(t) and y2(t). Increase the step size (delta t) and recalculate y1(t) and y2(t). See the difference. Calculate Fourier Transform of...

  • I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear...

    I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear all; format long; f=@(t,y)y*(1-y); y(1)=0.01; %%%% Exact solution [t1 y1]=ode45(f,[0 9],y(1)); figure; plot(t1,y1,'*'); hold on % Eular therom M=[32 64 128]; T=9; fprintf(' M Max error \n' ); for n=1:length(M) k=T/M(n); t=0:k:T; for h=1:length(t)-1 y(h+1)=y(h)+k*f(t(h),y(h)); end plot(t,y); hold on %%%...

  • t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c...

    t0 = 0; tf = 20; y0 = [10;60]; a = .8; b = .01; c = .6; d = .1; [t,y] = ode45(@f,[t0,tf],y0,[],a,b,c,d); u1 = y(:,1); u2 = y(:,2); % y in output has 2 columns corresponding to u1 and u2 figure(1); subplot(2,1,1); plot(t,u1,'b-+'); ylabel('u1'); subplot(2,1,2); plot(t,u2,'ro-'); ylabel('u2'); figure(2) plot(u1,u2); axis square; xlabel('u_1'); ylabel('u_2'); % plot the phase plot %---------------------------------------------------------------------- function dydt = f(t,y,a,b,c,d) u1 = y(1); u2 = y(2); dydt = [ a*u1-b*u1*u2 ; -c*u2+d*u1*u2 ]; end Only...

  • 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 =...

  • I have been trying this problem for over 8 hours. How do I make the Matlab code for the given problem. It has to move. - Use the . You may use cif to clear the figure for the next instant of time...

    I have been trying this problem for over 8 hours. How do I make the Matlab code for the given problem. It has to move. - Use the . You may use cif to clear the figure for the next instant of time The goal is the same as before except this time you will plot a moving 3 bar lin mechanism shown below kage. Use the L2 (k2,ya L3 The equations that govern the motion of this linkage are:...

  • The outputs are very close to the correct values so I assume I just typed an...

    The outputs are very close to the correct values so I assume I just typed an equation incorrectly, but I have not been able to find the error. Courses LMS integration Documentation Write a function to implement the 4th order Runge Kutta method function [ty] - r4(f, range, ich) where is an anonymous function that defines the differential equation range is a vector of length 2 that sets a time range for a range for the independent art the initial...

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