Error with square root function and powers in Matlab R2014b [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am carrying out a series of calculations using the sqrt() function. My colleagues and I have noticed that we get different results when using the same inputs. Has anyone encountered this problem before?
This is an example:
input1 = 4;
input2 = 8;
result = sqrt(input1^2 + input2^2)
Result then displays a different value from my colleagues result. We have contacted MathWorks about this issue and have yet to receive a reply.

My team and I came across the same problem a year or two ago.
MathWorks explained that the sqrt() function has an issue with powers when they are added. To overcome this issue and achieve the same result, square each term outside of the sqrt() function:
input1 = 4^2;
input2 = 8^2;
result = sqrt(input1 + input2)
This solved it for my team and I. MathWorks didn't clarify as to the reason for the issue, but told us they were in the process of updating their documentation (haven't seen anything as of yet).

Related

Sum Matlab from 0 to 10000 on function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
syms k
S1 = symsum(1/((2*k)+1)^2,k,0,1000)
The result is this
59039372973827482202940226722672826425297321906316082356858983822169051832268260251807527611479190413293513875429587706186073872918905490907386679472102966658686481651660967093301512141946288248492833396616338323741632085379508599235923841007033467883638349122388806376761808189104503262045883240287482992169819848342303098664924237976221795758421152603069387903705445513260596627332283139648508194960733619500093010571517561429904500013876585156927070119332440687162376758374919870699278800835146651318465663183182583101377584105366558079836223068786457324044080570317649838092783113721959819118571747662368360095513856052974454509201490370810246175872510881504730747209788019551000695511879992198550955686739483474761130248789609061549535677663474218135370195381615899214931316241080337028498241295985409686314819267606796712968280842464845294917738460317179001491697993067157425958639996885239616893392960282441289069600101430806922004624472226999315951355963789249300352610312601262349650287009275097201871774652260892220551489305368617001974326978428202443548923140478853569492070442010110016068635424791389124439271253578545895132216218268847919848655110002938693346760862649668457282775860633067627110099340660770861888592018701206483696615682617062811616008107086256694453990688805738127607846586853460003073465075155412119309273843527076321601670400373937698518621100907936577387919537592519265365346619712200304996044229704602647674114176291753575322917531444831938509001759491229575945273985556769609288625450013634760596805884195325794441020339210402987018058377081579351119704065092777310976461961832919116412535470810011337916688085616171422473409544885864650134157327448050685723673514545806331081542320899927
It is a number in this form a/b
Why is this happening??
Do you know how to do this in octave too?
k = (0:1000);
k_sum = sum(1./((2*k)+1).^2);
disp(k_sum)
It's interesting that you jumped straight to using syms when the basic matlab functions work perfectly well for this problem. Why is that?

Why I get this Error? (State Space) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Could someone explain me what I must change in my model?
Model
The error messages are pretty clear and self-explanatory. The reason you get the error is because B is of dimension 4x2 and you are trying to do B * Xr where Xr is of dimension 1. According to your equation, you need to do B*U where U = [dXr/dt; Xr];. However, using the derivative block is never a good idea in Simulink if you can avoid it, especially with a step input. Think about how you want to formulate the inputs to your state-space.

MATLAB help for cell disruption modelling [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
i keep getting the error "Error using -""Matrix dimensions must agree"
for this piece of code. Can anybody help me and identify where i'm going wrong? I should be getting 8 plots of f vs d.
P=500;
N=1:1:8;
a=-0.4;
b=-1;
Kd=700;
d50star=(1./(10.^(Kd*(N.^a)*(P-115).^b)))
w0=0.45;
d=0:0.1:10
d50N0=5;
if d50star < 0.33;
w=(1-(2.3*d50star))*w0
else
w=(3.4-(5.5*d50star))*w0
end
d50=(1-d50star)*d50N0;
f=1-(1./((1+exp((d-d50)/w))))
There are at least two errors in the script:
1) in the last line [f=1-(1./((1+exp((d-d50)/w))))]
d size is 1x101
d50 size is 1x8
The size inconsistency is related to the definition of:
N=1:1:8; and
d=0:0.1:10
2) depending on the algoroth, it could be ./w instead of /w
Hope this helps.

I is not a real numeric array of class SINGLE [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm using the computer vision: VLfeat library to compute a HOG descriptor of an image, and after inputing this code:
cellSize = 8 ;
hog = vl_hog(im, cellSize, 'verbose') ;
I get this error in MATLAB, and when I google it I really can't find any possible explanation:
Error using vl_hog
I is not a real numeric array of class SINGLE.
After going over the code (found here) I'm also not sure what the variable I is:
Hopefully, I haven't missed something elementary ...
library source
As the asker already found out, the I refers to the first input argument.
Hence this should solve the problem:
hog = vl_hog(single(im), cellSize, 'verbose')

need help for matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This figure illustrates my problem:
t (in the X1 calculation) value changes from 0 to etz. If its value reaches etz it has to start from 0 again and again.
This situation has to continue during simulation (I need a loop!). However, t is simulation time and I cannot force it to be zero. So maybe I need a parallel time to the simulation time but I don't how to create it.
Use modulo operator.
http://www.mathworks.com/help/matlab/ref/mod.html
For example:
X1 = abs((mod(t,e*tz)-e*tz/2)/(1.125*c*tz))
This part:
mod(t,e*tz)
Will be >= 0 and < e*tz and will repeat the way you want.
In the future, please provide a better title for your question. Also, providing a screen shot of your code is not the preferred way to include code.