Question

in MATLAB Write a program to plot the proportional error, the ratio of the simulation value...

in MATLAB Write a program to plot the proportional error, the ratio of the simulation value minus the exact solution to the exact solution. Produce the plot.

Homework Answers

Answer #1

%Script that demonstrates Euler integration for a first order problem using

%MATLAB.

%The problem to be solved is:

%y'(t)+2*y(t)=2-exp(-4*t)

%Note: This problem has a known exact solution

%y(t)=1+0.58*exp(-4*t)-0.5*exp(-2*t)

function ystar = Eulermethod20(n)

a=0;

b=5;

h=(b-a)/n;

t=0:h:5;%Initialize time variable

clear ystar;%wipe out old variable

ystar(1)=1.0;%Initial condition (same for approximation)

for i=1:length(t)-1, %Set up "for" loop

k1=2-exp(-4*t(i))-2*ystar(i); %Calculate the derivative

ystar(i+1)=ystar(i)+h*k1;%Estimate new value of y

end

%Exact solution

y=1+0.5*exp(-4*t)-0.5*exp(-2*t);

%Error calculation

percent_error=100*abs(y-ystar)./y;

%Plot approximate and exact solutions

plot(t,ystar,'b--',t,y,'r-',t,percent_error,'g');

legend('Approximate','Exact','Error');

title('Euler Approximation n=5000');

xlabel('Time');

ylabel('y*(t), y(t)');

Know the answer?
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
Similar Questions
Write a Matlab program to plot the cosine wave. That is plot y=cos(k1x) vs. x for...
Write a Matlab program to plot the cosine wave. That is plot y=cos(k1x) vs. x for x varying from 0 to 2pi radians. The value of k1 is given at the end of this document. You can choose the increment for x. Note that large values of the increment will give you a coarse graph. Note: Matlab has two functions to calculate the sine of an angle: sin(x) and sind(x). What is the difference between these two functions? Use help...
Write a MATLAB program to compute electric potential due to N multiplecharges. Show the relevant theory,...
Write a MATLAB program to compute electric potential due to N multiplecharges. Show the relevant theory, calculated example for one point charge(verify by MATLAB), and MATLAB calculation for N point charges. UseMATLAB to plot 3D potential plot around a single and multiple point charges.
Write a matlab program that takee a character (a-z) as an input and checks if that...
Write a matlab program that takee a character (a-z) as an input and checks if that is a vowel or not using switch statment? If the user inputs any other character, the program should display a proper error message.
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method...
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method (use the form of second-order Runge-Kutta method, Eqs(10.65),(10.66)). For function name and arguments use [x,y]=odeMIDPOINT(ODE,a,b,h,yINI). The input argument ODE is a name for the function that calculates dy/dx. It is a dummy name for the function that is imported into odeMIDPOINT. The arguments a and b define the domain of the solution, h is step size; yINI is initial value. The output arguments, x...
Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary...
Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary and gray scale, Image segmentation and extraction, draw and find the region of interest with a circle, Plot bounding box, Region extraction and histogram.
Write a MATLAB program to determine the factorial value of an input integer between 1 and...
Write a MATLAB program to determine the factorial value of an input integer between 1 and 30. You may NOT use the built-in factorial function. You must implement it using a for loop. Display the result back to the user with 2 decimal places (yes, 2 decimal places). The result should follow the following format:   The factorial value is *.xx
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys...
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys 1, A and B. Choose an appropriate sampling frequency. The DTMF frequencies are indicated in table 1.     Critically analyze the design specification.                                           Row/column 1209HZ 1336Hz 1477HZ 1633HZ 697 1 2 3 A 770 4 5 6 B 852 7 8 9 C 941 * 0 # D     Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for...
Q) Write a computer program to test the stability of any continuous-time LTI system.( using Matlab)...
Q) Write a computer program to test the stability of any continuous-time LTI system.( using Matlab) Test your program on the impulse response.   h(t)= e^(-2t) u(t) Attached the program (Matlab) file and a screen shot of the results.
MATLAB 2017b Write a program which will: Accept three numbers from the user: a, b and...
MATLAB 2017b Write a program which will: Accept three numbers from the user: a, b and c which can assume any value. Accept Dx and Dy for the calculations of the function Write a function which accept a, b, c, Dx and Dy and will draw the following surface Where x and y vary in the range of -10?x?10 -10?y?10. Allow the user to rerun the program and exit the program upon request.
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT