function [u] = suitem(A,b,u1,nb)
[n,n] = size(A) ;
u=u1 for i = 1 : nb
u= A*u +b
end
end

 채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 9일

0 개 추천

Other than having to fix the for being on the same line, it looks okay to me.
suitem(rand(8,8), rand, rand, 7)
ans = 8×8
5.9738 5.7873 6.4540 5.8167 5.9296 5.6976 6.9287 6.5290 6.3011 6.1045 6.8077 6.1355 6.2547 6.0097 7.3086 6.8868 6.9830 6.7651 7.5445 6.7995 6.9317 6.6601 8.0996 7.6322 6.8662 6.6519 7.4183 6.6857 6.8157 6.5487 7.9641 7.5045 7.3179 7.0894 7.9063 7.1255 7.2641 6.9795 8.4879 7.9982 7.8525 7.6073 8.4838 7.6460 7.7947 7.4894 9.1080 8.5824 5.8720 5.6887 6.3441 5.7176 5.8287 5.6005 6.8108 6.4178 5.0072 4.8508 5.4098 4.8755 4.9704 4.7757 5.8077 5.4726
function [u] = suitem(A,b,u1,nb)
[n,n] = size(A);
u=u1;
for i = 1 : nb
u= A*u +b;
end
end

댓글 수: 5

KARIM MANSOUR
KARIM MANSOUR 2021년 1월 12일
thank you walter
function [u] = suite(A,b,u1,nb)
[n,n] = size(A);
u=u1;
for i = 1 : nb
u= A*u +b;
end
end
A=[5/8 -1/4 1/8;1/4 0 1/4;1/8 -1/4 5/8];b=[1;-1;1];u1=[5;2;-4];m=20;p=m;
u=suite(A,b,u1;b)
u must be size [3,20] but i found it [3,1] please help
Why would it be 3 x 20? You create m=20 and you assign that to p, but you do not use m or p in the code.
%{
u=suite(A,b,u1;b)
%}
That is invalid syntax. Assuming you want
%{
u=suite(A,b,u1,b)
%}
then notice that you are passing b twice, and that the second one is in a place you expect a scalar.
I suspect what you want is
A = [5/8 -1/4 1/8;1/4 0 1/4;1/8 -1/4 5/8];
b = [1;-1;1];
u1 = [5;2;-4];
m = 20; p = m;
u = suite(A, b, u1, m)
u = 3×20
5.0000 3.1250 2.9688 3.0859 3.1934 3.2593 3.2953 3.3141 3.3236 3.3285 3.3309 3.3321 3.3327 3.3330 3.3332 3.3333 3.3333 3.3333 3.3333 3.3333 2.0000 -0.7500 -0.5625 -0.0781 0.2617 0.4561 0.5593 0.6125 0.6395 0.6530 0.6598 0.6633 0.6650 0.6658 0.6662 0.6665 0.6666 0.6666 0.6666 0.6667 -4.0000 -1.3750 0.7188 1.9609 2.6309 2.9780 3.1547 3.2437 3.2885 3.3109 3.3221 3.3277 3.3305 3.3319 3.3326 3.3330 3.3332 3.3332 3.3333 3.3333
function [u] = suite(A,b,u1,nb)
[n,n] = size(A);
u = u1(:);
for i = 2 : nb
u(:,i) = A * u(:,i-1) + b;
end
end
KARIM MANSOUR
KARIM MANSOUR 2021년 1월 13일
thank you this is what i want
KARIM MANSOUR
KARIM MANSOUR 2021년 1월 13일
Walter,check please https://fr.mathworks.com/matlabcentral/answers/716073-hilbert-matrix-come-on

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2021년 1월 9일

댓글:

2021년 1월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by