Suppose i need 100 power of say 1.5 then how can i get that .
Any formula how to get this in iphone .For example i need the value of 1.5^100 , then how can i get that in objective c.
Use the pow() function from math.h:
NSLog(#"%.f", pow(1.5,100) );
If you need any other math related operations, I would check out:
Objective-C Math functions
Related
I am a newbie in Python and I request help! Use Python to calculate this:
(((1+2)*3)/4)5
How do you calculate this in Python using double star operator? It shows errors when I try it this way:
print(((1+2)*3)/4)**5
As per my understnding on your code you should use the statement print((((1+2)*3)/4)**5) to calculate your operation. If you use * it means multiply or if you use ** it means to the power of.
I am trying to make a program to print maximum of 5 numbers using for loop and taking number input from user.
I know I can do it via max command by having a =[1,2,3,4,5]; and max(a);.
But trying out with for loop.
I don't know how to take an array in Scilab (I know their is matrix that we can take but don't know how to take input from user in matrix or in array in Scilab)
`a = [1,2,3,4,5];` //works fine but i want user should input numbers.
I know one way is using
a = input("First number:");
b = input("Second number:"); ... and so on upto fifth number
// i want to make it short like using array in C language
int a[5];
printf("Enter numbers");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
// Here in Scilab i don't know how i write it??
if I use int a[5]; i get error Undefined variable: a --error4
I know i can use mprintf & msscanf but question is i am not able to declare or take array data from user's end.
Please suggest me some way to make this program.
Also how to declare & take matrix data from user and declare & take array data from user.
Comments on your solution
Entering matrices
I think your solution is valid, however it could be frustrating for the user to keep providing entries if you have a lot of entries and you know you mistyped the first.
A nice function to have a look at is x_matrix. It provides an easy interface for editing matrices.
Functions
I also usually really prefer functions, it makes it much easier to reuse your code and validate and test small portions. Naturally in this problem the SciLab provided function max() should be used, but you stated you wanted to use a for loop.
Code example
Taking into account the above statements, here is a small working example. You could expand it to let the user first provide the matrix dimensions.
function maximum = findMax( numbers )
maximum = -1e99;
numberOfNumbers = length( numbers );
for i=1:numberOfNumbers
if( numbers(i) > maximum )
maximum = numbers(i);
end
end
return maximum;
endfunction
[result]=x_matrix("enter a matrix", zeros(5,5) );
foundMaximum = findMax(result);
disp( "Maximum is " + string( foundMaximum ) );
I managed to write this code it work's fine now.
But i want more answers also to learn more ways.
disp("Enter Numbers:"); // Enter first number on console then press enter key then type second number and again press enter to type third ..... so on to fifth.
for i = 1:5
x(i) = input('');
end
maximum = x(1)
for i=1:5
if(x(i)>maximum)then
maximum = x(i)
end
end
disp(maximum, "Maximum Number is");
Is it the correct way to write this program and taking input from user this way ??
Qestions remains How to declare & take matrix data from user and declare & take array data from user.
More Answers Needed.
I had a similar problem and found this nice way from the Scilab Help:
labels=["magnitude";"frequency";"phase "];
[ok,mag,freq,ph]=getvalue("define sine signal",labels,...
list("vec",1,"vec",1,"vec",1),["0.85";"10^2";"%pi/3"])
I liked it because you have labels and get a good overview over your data.
In the example above no for loop is included but lists can be created quite flexible and you can for example create the list in a for loop if you need that kind of pattern.
I'm having the following issue with my code. I've been trying to use some other posts that I found on line, like this one. But they didn't what I'm looking for.
My code uses a MATLAB Exchange function which optimize a numerical value that is important to be with 32 digits after the dot such as
0.59329669191989231613604260928696
The optimization function can be found here and it is called fminsearchbnd
The optimization function calculate this and store the value in a variable that I use all over my code. In order not to perform the optimization everytime I want to store the variable (I tried either on a *.mat and on a label in the string form.
But when I retrieve it, MATLAB transforms it in a double precision variable 'cutting' all the numbers after the 14th. However I need all of them because they are important!
Is it possible to read a number like that w/o using vpa() because with a symbolic value I can't do anything.
Any help is really appreciated.
Thanks
EDIT:
fminsearchbnd gives me this class(bb) -> double and when I want to see it on the workspace it is 0.586675392365899. But when I set formatSpec = '%.32f\n'; because I want to see all the numbers that the optimization gives me, typing set(editLabel,'String',num2str(bb,formatSpec))
You're trying to store/use a number that cannot be represented exactly in an IEEE754 64-bit double-precision floating point number.
I'm not sure how you got that number without using vpa() in the first place, since 64-bit double is Matlab's maximum of precision...
You could use the multiple precision toolbox by Ben Barrowes, or HPF by John d'Errico, also from the FEX. You'll have to convert/construct to/from string if you want to store/load it to/from file.
But I have to agree with John's comment there:
The fact is, most of the time, if you can't do it with a double, you
are doing something wrong
so...why exactly are those 32-or-more digits important?
I need help with a hard bonus question using MATLAB.
Question: You are given an array of structures named Stats. Each structure contains the following fields: BA, HomeRuns, Errors. Write a function that takes in that array and returns the MVP of the season. The MVP is defined as the player with the highest batting average(BA) given he has at least 25 home runs and at the most 5 errors.
The following should give you some ideas:
[Stats.HomeRuns]
ind = find( x > 25 );
max([Stats(ind).BA])
Seems like in Perl this should be easy or a module, but I have not found an easy answer yet. I have a calculated z normal score and the mean, but have not found an easy method to calculate the percentage. The solutions I have found are for looking it up using a statistics table, but it seems like something that common would have a module or something easy. (ie a z-score of -3 is -3 sigma and has a percentage of 0.1%). I don't want to have to build a table in perl and then interpolate if I don't need to. Anyone know?
I'm not 100% sure since the only description you gave is "the percentage", but I think the function you need is the cumulative probability function for the normal function. You can get this from the module Math::CDF.
use Math::CDF;
my $prob = Math::CDF::pnorm(-3);
printf "%.1f%%\n", $prob * 100; # Prints 0.1%