当前位置:网站首页>Matlab Error (Matrix dimensions must agree)

Matlab Error (Matrix dimensions must agree)

2022-07-07 03:10:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack

xOld =input(‘Enter initial guess: ‘);

errortmp =2;

counter =0;

while (errortmp>10^-10)

xNew =xOld – Jf3(xOld)\f3(xOld)

counter=counter+1

error=norm(xNew-xOld,inf)+4*eps*norm(xNew,inf)

if(error>=errortmp)

error(‘shit!’);

else

errortmp=error;

end

xOld = xNew;

pause

end

function J=Jf3(x)

J=[0 0 1 1;

x(3) x(4) x(1) x(2);

2*x(3)*x(1) 2*x(4)*(x(2)) x(1)^2 x(2)^2;

3*x(3)*x(1)^2 3*x(4)*(x(2))^2 x(1)^3 x(2)^3];

function y=f3(x)

y=[x(3)+x(4)-2;

x(3)*x(1) + x(4)*x(2);

x(3)*x(1)^2 + x(4)*x(2)^2 – (2/3);

x(3)*x(1)^3 + x(4)*x(2)^3];

end

// When the user enters a value . Be sure to enter a matrix, You can't just enter a value , Otherwise it will show :Matrix dimensions must agree

Input 1; // At this time, what we input is only a number

Input 1 2 2 3; // At this time, what we input is not matrix

Input [1 2 3 4 ] // At this time, what we input is not matrix

Input [1;2;3;4] // correct

This is from to , Input value table and table processing function are different , So the error code will be displayed

Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116791.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061935440734.html