How to input solution for the matrix in for loop.
3 views (last 30 days)
Show older comments
I need to show the out put that are each the column matrix. See the code
clear all;
u=inline('exp(-t)*cos(pi.*x-pi/2)','x','t');
f=inline('cos(pi.*x-pi/2)','x');
h=[0.1 0.05 0.01], k=[0.1 0.05 0.01] %x-step size h, t-step size k
n=size(h,2);
a=0; b=1;
T=0.4;
for i=1:n
x=[a:h(i):b];
t=[0:k(i):T];
N=size(x,2);
M=size(t,2);
w(:,1)=f(x) % This is error !!
end
How do I write ? Thanks.
0 Comments
Answers (1)
drummer
on 11 May 2020
Not sure where your variable w came from.
It is not clear, at least for me, why you mentioned x and h steps as a vector...Do you have to use variable steps?
Ex: step 1 = 0.1 step 2 = 0.05 step 3 = 0.01 so, iteratively:
i = 1, x = 0.10
i = 2, x = 0.15
i = 3, x = 0.16
i=4, x = 0.51 ... and so on?
This is a quick solution that came to mind...
clear all;
step1 = 0.1;
step2 = 0.05;
step3 = 0.01;
n=9;
arraySum = zeros(n,1);
Sum = 0;
for i = 1:3:n % arraySum refers to your x interval. are the steps variable?
arraySum(i) = step1 + Sum;
arraySum(i+1) = arraySum(i+1)+step2+arraySum(i);
arraySum(i+2) = arraySum(i+1)+step3;
Sum = arraySum(i)+arraySum(i+1)+arraySum(i+2); % sum the previous values
end
x = arraySum
f = cos((pi/2).*x)
plot(f,x)
xlim([0 1])
0 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!