Question

I have to do this in excel but I dont understand how to do that. I've never used excel for this.

the system Exercise 5. For this exercise you will approximate the solution of an undamped periodically forced mass-spring sys

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

MATLAB CODE:

clc;
clear all;
close all;

%functions for improved Euler method for w=1
w=1;
f=@(t,x,y) y;
g=@(t,x,y) -x+cos(w*t);

%step size
h=0.1;

%Initial guess
x_0=0; y_0=0;

%iteration for x and y using improved Euler method
x_huen(1)=x_0; y_huen(1)=y_0;
t_huen(1)=0; t_end=50;
n=(t_end-t_huen)/h;
for i=1:n
  
t_huen(i+1)=t_huen(i)+h;
m1=f(t_huen(i),x_huen(i),y_huen(i));
m2=g(t_huen(i),x_huen(i),y_huen(i));
  
p1=f(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
p2=g(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
  
x_huen(i+1)=x_huen(i)+(h/2)*(m1+p1);
y_huen(i+1)=y_huen(i)+(h/2)*(m2+p2);
  
end

figure(1)
plot(t_huen,x_huen)
xlabel('time in sec.')
ylabel('x(t)')
title('Improved Euler solution plot for w=1')

clear x_huen; clear y_huen; clear t_huen

%functions for improved Euler method for w=1
w=1.1;
f=@(t,x,y) y;
g=@(t,x,y) -x+cos(w*t);

%step size
h=0.1;

%Initial guess
x_0=0; y_0=0;

%iteration for x and y using improved Euler method
x_huen(1)=x_0; y_huen(1)=y_0;
t_huen(1)=0; t_end=150;
n=(t_end-t_huen)/h;
for i=1:n
  
t_huen(i+1)=t_huen(i)+h;
m1=f(t_huen(i),x_huen(i),y_huen(i));
m2=g(t_huen(i),x_huen(i),y_huen(i));
  
p1=f(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
p2=g(t_huen(i+1),x_huen(i)+h*m1,y_huen(i)+h*m2);
  
x_huen(i+1)=x_huen(i)+(h/2)*(m1+p1);
y_huen(i+1)=y_huen(i)+(h/2)*(m2+p2);
  
end

figure(2)
plot(t_huen,x_huen)
xlabel('time in sec.')
ylabel('x(t)')
title('Improved Euler solution plot for w=1.1')

clear x_huen; clear y_huen; clear t_huen

fprintf('\tFor w=1 the period of envelop is higher than that of w=1.1 \n')

OUTPUT:

Improved Euler solution plot for wa1. 10 2 -6 -10 50 100 150 time in secIN EXCEL FORMATE

Matlab code for Euler and Heuns method for 2d clear all close all 888888움움88,,88움움88888888888888움움88888888888888888888888888

%initial guess iteration for x and y using improved Euler method x _huen (1)x0; y_huen(1)-y_0 t_huen ( 1)=0; tend-150; n (t_e


Add a comment
Know the answer?
Add Answer to:
I have to do this in excel but I dont understand how to do that. I've never used excel for this.
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
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